Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Contains \Drupal\views_ui\Form\Ajax\Display.
*/
namespace Drupal\views_ui\Form\Ajax;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
Angie Byron
committed
use Drupal\views\ViewStorageInterface;
/**
* Provides a form for editing the Views display.
*/
class Display extends ViewsFormBase {
/**
* Constucts a new Display object.
*/
public function __construct($type = NULL) {
$this->setType($type);
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
public function getFormKey() {
return 'display';
}
/**
* {@inheritdoc}
Angie Byron
committed
*
* @todo Remove this and switch all usage of $form_state['section'] to
* $form_state['type'].
*/
public function getFormState(ViewStorageInterface $view, $display_id, $js) {
Dries Buytaert
committed
$form_state = parent::getFormState($view, $display_id, $js);
$form_state['section'] = $this->type;
return $form_state;
Angie Byron
committed
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
public function getForm(ViewStorageInterface $view, $display_id, $js, $type = NULL) {
$this->setType($type);
return parent::getForm($view, $display_id, $js);
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
Alex Pott
committed
public function getFormId() {
Angie Byron
committed
return 'views_ui_edit_display_form';
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
Dries Buytaert
committed
public function buildForm(array $form, FormStateInterface $form_state) {
$view = $form_state['view'];
Angie Byron
committed
$display_id = $form_state['display_id'];
Alex Pott
committed
$executable = $view->getExecutable();
$executable->setDisplay($display_id);
Angie Byron
committed
// Get form from the handler.
$form['options'] = array(
'#theme_wrappers' => array('container'),
'#attributes' => array('class' => array('scroll'), 'data-drupal-views-scroll' => TRUE),
Angie Byron
committed
);
$executable->display_handler->buildOptionsForm($form['options'], $form_state);
// The handler options form sets $form['#title'], which we need on the entire
// $form instead of just the ['options'] section.
$form['#title'] = $form['options']['#title'];
unset($form['options']['#title']);
// Move the override dropdown out of the scrollable section of the form.
if (isset($form['options']['override'])) {
$form['override'] = $form['options']['override'];
unset($form['options']['override']);
}
$name = NULL;
if (isset($form_state['update_name'])) {
$name = $form_state['update_name'];
}
$view->getStandardButtons($form, $form_state, 'views_ui_edit_display_form', $name);
return $form;
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
Dries Buytaert
committed
public function validateForm(array &$form, FormStateInterface $form_state) {
Alex Pott
committed
$form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id'])->validateOptionsForm($form['options'], $form_state);
Angie Byron
committed
if ($form_state->getErrors()) {
Angie Byron
committed
$form_state['rerender'] = TRUE;
}
}
/**
* {@inheritdoc}
Angie Byron
committed
*/
Dries Buytaert
committed
public function submitForm(array &$form, FormStateInterface $form_state) {
Alex Pott
committed
$form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id'])->submitOptionsForm($form['options'], $form_state);
Angie Byron
committed
Alex Pott
committed
$form_state['view']->cacheSet();