Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views_ui / src / Form / BasicSettingsForm.php
1 <?php
2
3 namespace Drupal\views_ui\Form;
4
5 use Drupal\Core\Config\ConfigFactoryInterface;
6 use Drupal\Core\Extension\ThemeHandlerInterface;
7 use Drupal\Core\Form\ConfigFormBase;
8 use Drupal\Core\Form\FormStateInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Form builder for the admin display defaults page.
13  *
14  * @internal
15  */
16 class BasicSettingsForm extends ConfigFormBase {
17
18   /**
19    * The theme handler.
20    *
21    * @var \Drupal\Core\Extension\ThemeHandlerInterface
22    */
23   protected $themeHandler;
24
25   /**
26    * Constructs a \Drupal\views_ui\Form\BasicSettingsForm object.
27    *
28    * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
29    *   The factory for configuration objects.
30    * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
31    *   The theme handler.
32    */
33   public function __construct(ConfigFactoryInterface $config_factory, ThemeHandlerInterface $theme_handler) {
34     parent::__construct($config_factory);
35
36     $this->themeHandler = $theme_handler;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public static function create(ContainerInterface $container) {
43     return new static(
44       $container->get('config.factory'),
45       $container->get('theme_handler')
46     );
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getFormId() {
53     return 'views_ui_admin_settings_basic';
54   }
55
56   /**
57    * {@inheritdoc}
58    */
59   protected function getEditableConfigNames() {
60     return ['views.settings'];
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function buildForm(array $form, FormStateInterface $form_state) {
67     $form = parent::buildForm($form, $form_state);
68
69     $config = $this->config('views.settings');
70     $options = [];
71     foreach ($this->themeHandler->listInfo() as $name => $theme) {
72       if ($theme->status) {
73         $options[$name] = $theme->info['name'];
74       }
75     }
76
77     // This is not currently a fieldset but we may want it to be later,
78     // so this will make it easier to change if we do.
79     $form['basic'] = [];
80
81     $form['basic']['ui_show_master_display'] = [
82       '#type' => 'checkbox',
83       '#title' => $this->t('Always show the master (default) display'),
84       '#default_value' => $config->get('ui.show.master_display'),
85     ];
86
87     $form['basic']['ui_show_advanced_column'] = [
88       '#type' => 'checkbox',
89       '#title' => $this->t('Always show advanced display settings'),
90       '#default_value' => $config->get('ui.show.advanced_column'),
91     ];
92
93     $form['basic']['ui_show_display_embed'] = [
94       '#type' => 'checkbox',
95       '#title' => t('Allow embedded displays'),
96       '#description' => t('Embedded displays can be used in code via views_embed_view().'),
97       '#default_value' => $config->get('ui.show.display_embed'),
98     ];
99
100     $form['basic']['ui_exposed_filter_any_label'] = [
101       '#type' => 'select',
102       '#title' => $this->t('Label for "Any" value on non-required single-select exposed filters'),
103       '#options' => ['old_any' => '<Any>', 'new_any' => $this->t('- Any -')],
104       '#default_value' => $config->get('ui.exposed_filter_any_label'),
105     ];
106
107     $form['live_preview'] = [
108       '#type' => 'details',
109       '#title' => $this->t('Live preview settings'),
110       '#open' => TRUE,
111     ];
112
113     $form['live_preview']['ui_always_live_preview'] = [
114       '#type' => 'checkbox',
115       '#title' => $this->t('Automatically update preview on changes'),
116       '#default_value' => $config->get('ui.always_live_preview'),
117     ];
118
119     $form['live_preview']['ui_show_preview_information'] = [
120       '#type' => 'checkbox',
121       '#title' => $this->t('Show information and statistics about the view during live preview'),
122       '#default_value' => $config->get('ui.show.preview_information'),
123     ];
124
125     $form['live_preview']['options'] = [
126       '#type' => 'container',
127       '#states' => [
128         'visible' => [
129           ':input[name="ui_show_preview_information"]' => ['checked' => TRUE],
130         ],
131       ],
132     ];
133
134     $form['live_preview']['options']['ui_show_sql_query_enabled'] = [
135       '#type' => 'checkbox',
136       '#title' => $this->t('Show the SQL query'),
137       '#default_value' => $config->get('ui.show.sql_query.enabled'),
138     ];
139
140     $form['live_preview']['options']['ui_show_sql_query_where'] = [
141       '#type' => 'radios',
142       '#states' => [
143         'visible' => [
144           ':input[name="ui_show_sql_query_enabled"]' => ['checked' => TRUE],
145         ],
146       ],
147       '#title' => t('Show SQL query'),
148       '#options' => [
149         'above' => $this->t('Above the preview'),
150         'below' => $this->t('Below the preview'),
151       ],
152       '#default_value' => $config->get('ui.show.sql_query.where'),
153     ];
154
155     $form['live_preview']['options']['ui_show_performance_statistics'] = [
156       '#type' => 'checkbox',
157       '#title' => $this->t('Show performance statistics'),
158       '#default_value' => $config->get('ui.show.performance_statistics'),
159     ];
160
161     $form['live_preview']['options']['ui_show_additional_queries'] = [
162       '#type' => 'checkbox',
163       '#title' => $this->t('Show other queries run during render during live preview'),
164       '#description' => $this->t("Drupal has the potential to run many queries while a view is being rendered. Checking this box will display every query run during view render as part of the live preview."),
165       '#default_value' => $config->get('ui.show.additional_queries'),
166     ];
167
168     return $form;
169   }
170
171   /**
172    * {@inheritdoc}
173    */
174   public function submitForm(array &$form, FormStateInterface $form_state) {
175     $this->config('views.settings')
176       ->set('ui.show.master_display', $form_state->getValue('ui_show_master_display'))
177       ->set('ui.show.advanced_column', $form_state->getValue('ui_show_advanced_column'))
178       ->set('ui.show.display_embed', $form_state->getValue('ui_show_display_embed'))
179       ->set('ui.exposed_filter_any_label', $form_state->getValue('ui_exposed_filter_any_label'))
180       ->set('ui.always_live_preview', $form_state->getValue('ui_always_live_preview'))
181       ->set('ui.show.preview_information', $form_state->getValue('ui_show_preview_information'))
182       ->set('ui.show.sql_query.where', $form_state->getValue('ui_show_sql_query_where'))
183       ->set('ui.show.sql_query.enabled', $form_state->getValue('ui_show_sql_query_enabled'))
184       ->set('ui.show.performance_statistics', $form_state->getValue('ui_show_performance_statistics'))
185       ->set('ui.show.additional_queries', $form_state->getValue('ui_show_additional_queries'))
186       ->save();
187
188     parent::submitForm($form, $form_state);
189   }
190
191 }