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