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.
13 class Display extends ViewsFormBase {
16 * Constructs a new Display object.
18 public function __construct($type = NULL) {
19 $this->setType($type);
25 public function getFormKey() {
32 * @todo Remove this and switch all usage of $form_state->get('section') to
33 * $form_state->get('type').
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);
44 public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL) {
45 $this->setType($type);
46 return parent::getForm($view, $display_id, $js);
52 public function getFormId() {
53 return 'views_ui_edit_display_form';
59 public function buildForm(array $form, FormStateInterface $form_state) {
60 $view = $form_state->get('view');
61 $display_id = $form_state->get('display_id');
63 $executable = $view->getExecutable();
64 if (!$executable->setDisplay($display_id)) {
65 $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
69 // Get form from the handler.
71 '#theme_wrappers' => ['container'],
72 '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
74 $executable->display_handler->buildOptionsForm($form['options'], $form_state);
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']);
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']);
87 $name = $form_state->get('update_name');
88 $view->getStandardButtons($form, $form_state, 'views_ui_edit_display_form', $name);
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);
100 if ($form_state->getErrors()) {
101 $form_state->set('rerender', TRUE);
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);