Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / views / src / Plugin / Menu / Form / ViewsMenuLinkForm.php
1 <?php
2
3 namespace Drupal\views\Plugin\Menu\Form;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\Core\Menu\Form\MenuLinkDefaultForm;
7
8 /**
9  * Provides a form to edit Views menu links.
10  *
11  * This provides the feature to edit the title and description, in contrast to
12  * the default menu link form.
13  *
14  * @see \Drupal\views\Plugin\Menu\ViewsMenuLink
15  */
16 class ViewsMenuLinkForm extends MenuLinkDefaultForm {
17
18   /**
19    * The edited views menu link.
20    *
21    * @var \Drupal\views\Plugin\Menu\ViewsMenuLink
22    */
23   protected $menuLink;
24
25   /**
26    * {@inheritdoc}
27    */
28   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
29
30     // Put the title field first.
31     $form['title'] = [
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(),
37       '#weight' => -10,
38     ];
39
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(),
47       '#weight' => -5,
48     ];
49
50     $form += parent::buildConfigurationForm($form, $form_state);
51
52     $form['info']['#weight'] = -8;
53     $form['path']['#weight'] = -7;
54
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]);
60     }
61     else {
62       $message = $this->t('This link is provided by the Views module from view %label.', ['%label' => $label]);
63     }
64     $form['info']['#title'] = $message;
65     return $form;
66   }
67
68   /**
69    * {@inheritdoc}
70    */
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');
75
76     return $definition;
77   }
78
79 }