Backup of db before drupal security update
[yaffs-website] / web / core / modules / views_ui / src / Form / Ajax / ConfigHandlerGroup.php
1 <?php
2
3 namespace Drupal\views_ui\Form\Ajax;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Views;
7 use Drupal\views\ViewEntityInterface;
8 use Drupal\views\ViewExecutable;
9
10 /**
11  * Provides a form for configuring grouping information for a Views UI handler.
12  */
13 class ConfigHandlerGroup extends ViewsFormBase {
14
15   /**
16    * Constructs a new ConfigHandlerGroup object.
17    */
18   public function __construct($type = NULL, $id = NULL) {
19     $this->setType($type);
20     $this->setID($id);
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function getFormKey() {
27     return 'handler-group';
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function getForm(ViewEntityInterface $view, $display_id, $js, $type = NULL, $id = NULL) {
34     $this->setType($type);
35     $this->setID($id);
36     return parent::getForm($view, $display_id, $js);
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function getFormId() {
43     return 'views_ui_config_item_group_form';
44   }
45
46   /**
47    * {@inheritdoc}
48    */
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');
54
55     $form = [
56       'options' => [
57         '#tree' => TRUE,
58         '#theme_wrappers' => ['container'],
59         '#attributes' => ['class' => ['scroll'], 'data-drupal-views-scroll' => TRUE],
60       ],
61     ];
62     $executable = $view->getExecutable();
63     if (!$executable->setDisplay($display_id)) {
64       $form['markup'] = ['#markup' => $this->t('Invalid display id @display', ['@display' => $display_id])];
65       return $form;
66     }
67
68     $executable->initQuery();
69
70     $item = $executable->getHandler($display_id, $type, $id);
71
72     if ($item) {
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']])];
76       }
77       else {
78         $handler->init($executable, $executable->display_handler, $item);
79         $types = ViewExecutable::getHandlerTypes();
80
81         $form['#title'] = $this->t('Configure aggregation settings for @type %item', ['@type' => $types[$type]['lstitle'], '%item' => $handler->adminLabel()]);
82
83         $handler->buildGroupByForm($form['options'], $form_state);
84         $form_state->set('handler', $handler);
85       }
86
87       $view->getStandardButtons($form, $form_state, 'views_ui_config_item_group_form');
88     }
89     return $form;
90   }
91
92   /**
93    * {@inheritdoc}
94    */
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');
99
100     $handler = Views::handlerManager($type)->getHandler($item);
101     $executable = $view->getExecutable();
102     $handler->init($executable, $executable->display_handler, $item);
103
104     $handler->submitGroupByForm($form, $form_state);
105
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);
108
109     // Write to cache
110     $view->cacheSet();
111   }
112
113 }