Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views_ui / src / Form / Ajax / Display.php
1 <?php
2
3 namespace Drupal\views_ui\Form\Ajax;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\ViewEntityInterface;
7
8 /**
9  * Provides a form for editing the Views display.
10  *
11  * @internal
12  */
13 class Display extends ViewsFormBase {
14
15   /**
16    * Constructs a new Display object.
17    */
18   public function __construct($type = NULL) {
19     $this->setType($type);
20   }
21
22   /**
23    * {@inheritdoc}
24    */
25   public function getFormKey() {
26     return 'display';
27   }
28
29   /**
30    * {@inheritdoc}
31    *
32    * @todo Remove this and switch all usage of $form_state->get('section') to
33    *   $form_state->get('type').
34    */
35   public function getFormState(ViewEntityInterface $view, $display_id, $js) {
36     $form_state = parent::getFormState($view, $display_id, $js);
37     $form_state->set('section', $this->type);
38     return $form_state;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
45     $this->setType($type);
46     return parent::getForm($view, $display_id, $js);
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getFormId() {
53     return 'views_ui_edit_display_form';
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   public function buildForm(array $form, FormStateInterface $form_state) {
60     $view = $form_state->get('view');
61     $display_id = $form_state->get('display_id');
62
63     $executable = $view->getExecutable();
64     if (!$executable->setDisplay($display_id)) {
65       $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
66       return $form;
67     }
68
69     // Get form from the handler.
70     $form['options'] = [
71       '#theme_wrappers' => ['container'],
72       '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
73     ];
74     $executable->display_handler->buildOptionsForm($form['options'], $form_state);
75
76     // The handler options form sets $form['#title'], which we need on the entire
77     // $form instead of just the ['options'] section.
78     $form['#title'] = $form['options']['#title'];
79     unset($form['options']['#title']);
80
81     // Move the override dropdown out of the scrollable section of the form.
82     if (isset($form['options']['override'])) {
83       $form['override'] = $form['options']['override'];
84       unset($form['options']['override']);
85     }
86
87     $name = $form_state->get('update_name');
88     $view->getStandardButtons($form, $form_state, 'views_ui_edit_display_form', $name);
89     return $form;
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function validateForm(array &$form, FormStateInterface $form_state) {
96     $view = $form_state->get('view');
97     $display_id = $form_state->get('display_id');
98     $view->getExecutable()->displayHandlers->get($display_id)->validateOptionsForm($form['options'], $form_state);
99
100     if ($form_state->getErrors()) {
101       $form_state->set('rerender', TRUE);
102     }
103   }
104
105   /**
106    * {@inheritdoc}
107    */
108   public function submitForm(array &$form, FormStateInterface $form_state) {
109     $view = $form_state->get('view');
110     $display_id = $form_state->get('display_id');
111     $view->getExecutable()->displayHandlers->get($display_id)->submitOptionsForm($form['options'], $form_state);
112
113     $view->cacheSet();
114   }
115
116 }