3 namespace Drupal\views\Plugin\Menu\Form;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Menu\Form\MenuLinkDefaultForm;
9 * Provides a form to edit Views menu links.
11 * This provides the feature to edit the title and description, in contrast to
12 * the default menu link form.
14 * @see \Drupal\views\Plugin\Menu\ViewsMenuLink
16 class ViewsMenuLinkForm extends MenuLinkDefaultForm {
19 * The edited views menu link.
21 * @var \Drupal\views\Plugin\Menu\ViewsMenuLink
28 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
30 // Put the title field first.
32 '#type' => 'textfield',
33 '#title' => $this->t('Title'),
34 // @todo Ensure that the view is not loaded with a localized title.
35 // https://www.drupal.org/node/2309507
36 '#default_value' => $this->menuLink->getTitle(),
40 $form['description'] = [
41 '#type' => 'textfield',
42 '#title' => $this->t('Description'),
43 '#description' => $this->t('Shown when hovering over the menu link.'),
44 // @todo Ensure that the view is not loaded with a localized description.
45 // https://www.drupal.org/node/2309507
46 '#default_value' => $this->menuLink->getDescription(),
50 $form += parent::buildConfigurationForm($form, $form_state);
52 $form['info']['#weight'] = -8;
53 $form['path']['#weight'] = -7;
55 $view = $this->menuLink->loadView();
56 $id = $view->storage->id();
57 $label = $view->storage->label();
58 if ($this->moduleHandler->moduleExists('views_ui')) {
59 $message = $this->t('This link is provided by the Views module. The path can be changed by editing the view <a href=":url">@label</a>', [':url' => \Drupal::url('entity.view.edit_form', ['view' => $id]), '@label' => $label]);
62 $message = $this->t('This link is provided by the Views module from view %label.', ['%label' => $label]);
64 $form['info']['#title'] = $message;
71 public function extractFormValues(array &$form, FormStateInterface $form_state) {
72 $definition = parent::extractFormValues($form, $form_state);
73 $definition['title'] = $form_state->getValue('title');
74 $definition['description'] = $form_state->getValue('description');