Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / core / modules / views_ui / src / Form / Ajax / EditDetails.php
1 <?php
2
3 namespace Drupal\views_ui\Form\Ajax;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Views;
7
8 /**
9  * Provides a form for editing the details of a View.
10  *
11  * @internal
12  */
13 class EditDetails extends ViewsFormBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function getFormKey() {
19     return 'edit-details';
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function getFormId() {
26     return 'views_ui_edit_details_form';
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function buildForm(array $form, FormStateInterface $form_state) {
33     $view = $form_state->get('view');
34
35     $form['#title'] = $this->t('Name and description');
36     $form['#section'] = 'details';
37
38     $form['details'] = [
39       '#theme_wrappers' => ['container'],
40       '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
41     ];
42     $form['details']['label'] = [
43       '#type' => 'textfield',
44       '#title' => t('Administrative name'),
45       '#default_value' => $view->label(),
46     ];
47     $form['details']['langcode'] = [
48       '#type' => 'language_select',
49       '#title' => $this->t('View language'),
50       '#description' => $this->t('Language of labels and other textual elements in this view.'),
51       '#default_value' => $view->get('langcode'),
52     ];
53     $form['details']['description'] = [
54        '#type' => 'textfield',
55        '#title' => t('Administrative description'),
56        '#default_value' => $view->get('description'),
57      ];
58     $form['details']['tag'] = [
59       '#type' => 'textfield',
60       '#title' => t('Administrative tags'),
61       '#description' => t('Enter a comma-separated list of words to describe your view.'),
62       '#default_value' => $view->get('tag'),
63       '#autocomplete_route_name' => 'views_ui.autocomplete',
64     ];
65
66     $view->getStandardButtons($form, $form_state, 'views_ui_edit_details_form');
67     return $form;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function submitForm(array &$form, FormStateInterface $form_state) {
74     $view = $form_state->get('view');
75     foreach ($form_state->getValues() as $key => $value) {
76       // Only save values onto the view if they're actual view properties
77       // (as opposed to 'op' or 'form_build_id').
78       if (isset($form['details'][$key])) {
79         $view->set($key, $value);
80       }
81     }
82     $bases = Views::viewsData()->fetchBaseTables();
83     $page_title = $view->label();
84     if (isset($bases[$view->get('base_table')])) {
85       $page_title .= ' (' . $bases[$view->get('base_table')]['title'] . ')';
86     }
87     $form_state->set('page_title', $page_title);
88
89     $view->cacheSet();
90   }
91
92 }