/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($this->linkitProfile->getAttributes()->has($this->linkitAttribute->getPluginId())) { $this->linkitProfile->removeAttribute($this->linkitAttribute->getPluginId()); $this->linkitProfile->save(); drupal_set_message($this->t('The attribute %label has been deleted.', ['%label' => $this->linkitAttribute->getLabel()])); $this->logger('linkit')->notice('The attribute %label has been deleted in the @profile profile.', [ '%label' => $this->linkitAttribute->getLabel(), '@profile' => $this->linkitProfile->label(), ]); } $form_state->setRedirect('linkit.attributes', [ 'linkit_profile' => $this->linkitProfile->id(), ]); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { foreach ($form_state->getValue('plugins') as $id => $plugin_data) { if ($this->linkitProfile->getAttributes()->has($id)) { $this->linkitProfile->getAttribute($id)->setWeight($plugin_data['weight']); } } $this->linkitProfile->save(); }
/** * {@inheritdoc} * * @param \Drupal\filter\Entity\FilterFormat $filter_format * The filter format for which this dialog corresponds. */ public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) { // The default values are set directly from \Drupal::request()->request, // provided by the editor plugin opening the dialog. $user_input = $form_state->getUserInput(); $input = isset($user_input['editor_object']) ? $user_input['editor_object'] : []; /** @var \Drupal\editor\EditorInterface $editor */ $editor = $this->editorStorage->load($filter_format->id()); $linkit_profile_id = $editor->getSettings()['plugins']['linkit']['linkit_profile']; $this->linkitProfile = $this->linkitProfileStorage->load($linkit_profile_id); $form['#tree'] = TRUE; $form['#attached']['library'][] = 'editor/drupal.editor.dialog'; $form['#prefix'] = '<div id="linkit-editor-dialog-form">'; $form['#suffix'] = '</div>'; // Everything under the "attributes" key is merged directly into the // generated link tag's attributes. $form['attributes']['href'] = [ '#title' => $this->t('Link'), '#type' => 'linkit', '#default_value' => isset($input['href']) ? $input['href'] : '', '#description' => $this->t('Start typing to find content or paste a URL.'), '#autocomplete_route_name' => 'linkit.autocomplete', '#autocomplete_route_parameters' => [ 'linkit_profile_id' => $linkit_profile_id ], '#weight' => 0, ]; $this->addAttributes($form, $form_state, $this->linkitProfile->getAttributes()); $form['actions'] = [ '#type' => 'actions', ]; $form['actions']['save_modal'] = [ '#type' => 'submit', '#value' => $this->t('Save'), '#submit' => [], '#ajax' => [ 'callback' => '::submitForm', 'event' => 'click', ], ]; return $form; }
/** * Builds the table rows. * * Only attributes that is not already applied to the profile are shown. * * @return array * An array of table rows. */ private function buildRows() { $rows = []; $applied_plugins = $this->linkitProfile->getAttributes()->getConfiguration(); $all_plugins = $this->manager->getDefinitions(); uasort($all_plugins, function ($a, $b) { return strnatcasecmp($a['label'], $b['label']); }); foreach (array_diff_key($all_plugins, $applied_plugins) as $definition) { /** @var \Drupal\linkit\AttributeInterface $plugin */ $plugin = $this->manager->createInstance($definition['id']); $row = [ 'label' => (string) $plugin->getLabel(), 'description' => (string) $plugin->getDescription(), ]; $rows[$plugin->getPluginId()] = $row; } return $rows; }