Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / views_ui / src / Form / AdvancedSettingsForm.php
1 <?php
2
3 namespace Drupal\views_ui\Form;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\views\Views;
8
9 /**
10  * Form builder for the advanced admin settings page.
11  *
12  * @internal
13  */
14 class AdvancedSettingsForm extends ConfigFormBase {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function getFormId() {
20     return 'views_ui_admin_settings_advanced';
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function getEditableConfigNames() {
27     return ['views.settings'];
28   }
29
30   /**
31    * {@inheritdoc}
32    */
33   public function buildForm(array $form, FormStateInterface $form_state) {
34     $form = parent::buildForm($form, $form_state);
35
36     $config = $this->config('views.settings');
37     $form['cache'] = [
38       '#type' => 'details',
39       '#title' => $this->t('Caching'),
40       '#open' => TRUE,
41     ];
42
43     $form['cache']['skip_cache'] = [
44       '#type' => 'checkbox',
45       '#title' => $this->t('Disable views data caching'),
46       '#description' => $this->t("Views caches data about tables, modules and views available, to increase performance. By checking this box, Views will skip this cache and always rebuild this data when needed. This can have a serious performance impact on your site."),
47       '#default_value' => $config->get('skip_cache'),
48     ];
49
50     $form['cache']['clear_cache'] = [
51       '#type' => 'submit',
52       '#value' => $this->t("Clear Views' cache"),
53       '#submit' => ['::cacheSubmit'],
54     ];
55
56     $form['debug'] = [
57       '#type' => 'details',
58       '#title' => $this->t('Debugging'),
59       '#open' => TRUE,
60     ];
61
62     $form['debug']['sql_signature'] = [
63       '#type' => 'checkbox',
64       '#title' => $this->t('Add Views signature to all SQL queries'),
65       '#description' => $this->t("All Views-generated queries will include the name of the views and display 'view-name:display-name' as a string at the end of the SELECT clause. This makes identifying Views queries in database server logs simpler, but should only be used when troubleshooting."),
66
67       '#default_value' => $config->get('sql_signature'),
68     ];
69
70     $options = Views::fetchPluginNames('display_extender');
71     if (!empty($options)) {
72       $form['extenders'] = [
73         '#type' => 'details',
74         '#open' => TRUE,
75       ];
76       $form['extenders']['display_extenders'] = [
77         '#title' => $this->t('Display extenders'),
78         '#default_value' => array_filter($config->get('display_extenders')),
79         '#options' => $options,
80         '#type' => 'checkboxes',
81         '#description' => $this->t('Select extensions of the views interface.'),
82       ];
83     }
84
85     return $form;
86   }
87
88   /**
89    * {@inheritdoc}
90    */
91   public function submitForm(array &$form, FormStateInterface $form_state) {
92     $this->config('views.settings')
93       ->set('skip_cache', $form_state->getValue('skip_cache'))
94       ->set('sql_signature', $form_state->getValue('sql_signature'))
95       ->set('display_extenders', $form_state->getValue('display_extenders', []))
96       ->save();
97
98     parent::submitForm($form, $form_state);
99   }
100
101   /**
102    * Submission handler to clear the Views cache.
103    */
104   public function cacheSubmit() {
105     views_invalidate_cache();
106     $this->messenger()->addStatus($this->t('The cache has been cleared.'));
107   }
108
109 }