3 namespace Drupal\views_ui\Form\Ajax;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Views;
7 use Drupal\views\ViewEntityInterface;
8 use Drupal\views\ViewExecutable;
11 * Provides a form for configuring grouping information for a Views UI handler.
13 class ConfigHandlerGroup extends ViewsFormBase {
16 * Constructs a new ConfigHandlerGroup object.
18 public function __construct($type = NULL, $id = NULL) {
19 $this->setType($type);
26 public function getFormKey() {
27 return 'handler-group';
33 public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
34 $this->setType($type);
36 return parent::getForm($view, $display_id, $js);
42 public function getFormId() {
43 return 'views_ui_config_item_group_form';
49 public function buildForm(array $form, FormStateInterface $form_state) {
50 $view = $form_state->get('view');
51 $display_id = $form_state->get('display_id');
52 $type = $form_state->get('type');
53 $id = $form_state->get('id');
58 '#theme_wrappers' => ['container'],
59 '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
62 $executable = $view->getExecutable();
63 if (!$executable->setDisplay($display_id)) {
64 $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
68 $executable->initQuery();
70 $item = $executable->getHandler($display_id, $type, $id);
73 $handler = $executable->display_handler->getHandler($type, $id);
74 if (empty($handler)) {
75 $form['markup'] = ['#markup' => $this->t("Error: handler for @table > @field doesn't exist!", ['@table' => $item['table'], '@field' => $item['field']])];
78 $handler->init($executable, $executable->display_handler, $item);
79 $types = ViewExecutable::getHandlerTypes();
81 $form['#title'] = $this->t('Configure aggregation settings for @type %item', ['@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()]);
83 $handler->buildGroupByForm($form['options'], $form_state);
84 $form_state->set('handler', $handler);
87 $view->getStandardButtons($form, $form_state, 'views_ui_config_item_group_form');
95 public function submitForm(array &$form, FormStateInterface $form_state) {
96 $view = $form_state->get('view');
97 $item = &$form_state->get('handler')->options;
98 $type = $form_state->get('type');
100 $handler = Views::handlerManager($type)->getHandler($item);
101 $executable = $view->getExecutable();
102 $handler->init($executable, $executable->display_handler, $item);
104 $handler->submitGroupByForm($form, $form_state);
106 // Store the item back on the view
107 $executable->setHandler($form_state->get('display_id'), $form_state->get('type'), $form_state->get('id'), $item);