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.
14 class ConfigHandlerExtra extends ViewsFormBase {
17 * Constructs a new ConfigHandlerExtra object.
19 public function __construct($type = NULL, $id = NULL) {
20 $this->setType($type);
27 public function getFormKey() {
28 return 'handler-extra';
34 public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
35 $this->setType($type);
37 return parent::getForm($view, $display_id, $js);
43 public function getFormId() {
44 return 'views_ui_config_item_extra_form';
50 public function buildForm(array $form, FormStateInterface $form_state) {
51 $view = $form_state->get('view');
52 $display_id = $form_state->get('display_id');
53 $type = $form_state->get('type');
54 $id = $form_state->get('id');
59 '#theme_wrappers' => ['container'],
60 '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
63 $executable = $view->getExecutable();
64 if (!$executable->setDisplay($display_id)) {
65 $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
68 $item = $executable->getHandler($display_id, $type, $id);
71 $handler = $executable->display_handler->getHandler($type, $id);
72 if (empty($handler)) {
73 $form['markup'] = ['#markup' => $this->t("Error: handler for @table > @field doesn't exist!", ['@table' => $item['table'], '@field' => $item['field']])];
76 $handler->init($executable, $executable->display_handler, $item);
77 $types = ViewExecutable::getHandlerTypes();
79 $form['#title'] = $this->t('Configure extra settings for @type %item', ['@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()]);
81 $form['#section'] = $display_id . '-' . $type . '-' . $id;
83 // Get form from the handler.
84 $handler->buildExtraOptionsForm($form['options'], $form_state);
85 $form_state->set('handler', $handler);
88 $view->getStandardButtons($form, $form_state, 'views_ui_config_item_extra_form');
96 public function validateForm(array &$form, FormStateInterface $form_state) {
97 $form_state->get('handler')->validateExtraOptionsForm($form['options'], $form_state);
103 public function submitForm(array &$form, FormStateInterface $form_state) {
104 $view = $form_state->get('view');
105 $handler = $form_state->get('handler');
106 // Run it through the handler's submit function.
107 $handler->submitExtraOptionsForm($form['options'], $form_state);
108 $item = $handler->options;
110 // Store the data we're given.
111 foreach ($form_state->getValue('options') as $key => $value) {
112 $item[$key] = $value;
115 // Store the item back on the view
116 $view->getExecutable()->setHandler($form_state->get('display_id'), $form_state->get('type'), $form_state->get('id'), $item);