3 namespace Drupal\views_ui\Form\Ajax;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\ViewEntityInterface;
7 use Drupal\views\ViewExecutable;
10 * Provides a form for configuring extra information for a Views UI item.
12 class ConfigHandlerExtra extends ViewsFormBase {
15 * Constructs a new ConfigHandlerExtra object.
17 public function __construct($type = NULL, $id = NULL) {
18 $this->setType($type);
25 public function getFormKey() {
26 return 'handler-extra';
32 public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
33 $this->setType($type);
35 return parent::getForm($view, $display_id, $js);
41 public function getFormId() {
42 return 'views_ui_config_item_extra_form';
48 public function buildForm(array $form, FormStateInterface $form_state) {
49 $view = $form_state->get('view');
50 $display_id = $form_state->get('display_id');
51 $type = $form_state->get('type');
52 $id = $form_state->get('id');
57 '#theme_wrappers' => ['container'],
58 '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
61 $executable = $view->getExecutable();
62 if (!$executable->setDisplay($display_id)) {
63 $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
66 $item = $executable->getHandler($display_id, $type, $id);
69 $handler = $executable->display_handler->getHandler($type, $id);
70 if (empty($handler)) {
71 $form['markup'] = ['#markup' => $this->t("Error: handler for @table > @field doesn't exist!", ['@table' => $item['table'], '@field' => $item['field']])];
74 $handler->init($executable, $executable->display_handler, $item);
75 $types = ViewExecutable::getHandlerTypes();
77 $form['#title'] = $this->t('Configure extra settings for @type %item', ['@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()]);
79 $form['#section'] = $display_id . '-' . $type . '-' . $id;
81 // Get form from the handler.
82 $handler->buildExtraOptionsForm($form['options'], $form_state);
83 $form_state->set('handler', $handler);
86 $view->getStandardButtons($form, $form_state, 'views_ui_config_item_extra_form');
94 public function validateForm(array &$form, FormStateInterface $form_state) {
95 $form_state->get('handler')->validateExtraOptionsForm($form['options'], $form_state);
101 public function submitForm(array &$form, FormStateInterface $form_state) {
102 $view = $form_state->get('view');
103 $handler = $form_state->get('handler');
104 // Run it through the handler's submit function.
105 $handler->submitExtraOptionsForm($form['options'], $form_state);
106 $item = $handler->options;
108 // Store the data we're given.
109 foreach ($form_state->getValue('options') as $key => $value) {
110 $item[$key] = $value;
113 // Store the item back on the view
114 $view->getExecutable()->setHandler($form_state->get('display_id'), $form_state->get('type'), $form_state->get('id'), $item);