3 namespace Drupal\views_ui\Form\Ajax;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\ViewEntityInterface;
9 * Provides a form for editing the Views display.
11 class Display extends ViewsFormBase {
14 * Constructs a new Display object.
16 public function __construct($type = NULL) {
17 $this->setType($type);
23 public function getFormKey() {
30 * @todo Remove this and switch all usage of $form_state->get('section') to
31 * $form_state->get('type').
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);
42 public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
43 $this->setType($type);
44 return parent::getForm($view, $display_id, $js);
50 public function getFormId() {
51 return 'views_ui_edit_display_form';
57 public function buildForm(array $form, FormStateInterface $form_state) {
58 $view = $form_state->get('view');
59 $display_id = $form_state->get('display_id');
61 $executable = $view->getExecutable();
62 if (!$executable->setDisplay($display_id)) {
63 $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
67 // Get form from the handler.
69 '#theme_wrappers' => ['container'],
70 '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
72 $executable->display_handler->buildOptionsForm($form['options'], $form_state);
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']);
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']);
85 $name = $form_state->get('update_name');
86 $view->getStandardButtons($form, $form_state, 'views_ui_edit_display_form', $name);
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);
98 if ($form_state->getErrors()) {
99 $form_state->set('rerender', TRUE);
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);