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