BasicSettingsForm.php 5.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Contains \Drupal\views_ui\Form\BasicSettingsForm.
 */

namespace Drupal\views_ui\Form;

10
11
use Drupal\system\SystemConfigFormBase;

12
13
14
/**
 * Form builder for the admin display defaults page.
 */
15
class BasicSettingsForm extends SystemConfigFormBase {
16
17
18
19
20
21
22
23
24
25
26
27

  /**
   * Implements \Drupal\Core\Form\FormInterface::getFormID().
   */
  public function getFormID() {
    return 'views_ui_admin_settings_basic';
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::buildForm().
   */
  public function buildForm(array $form, array &$form_state) {
28
29
    $form = parent::buildForm($form, $form_state);

30
    $config = $this->configFactory->get('views.settings');
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    $options = array();
    foreach (list_themes() as $name => $theme) {
      if ($theme->status) {
        $options[$name] = $theme->info['name'];
      }
    }

    // This is not currently a fieldset but we may want it to be later,
    // so this will make it easier to change if we do.
    $form['basic'] = array();

    $form['basic']['ui_show_master_display'] = array(
      '#type' => 'checkbox',
      '#title' => t('Always show the master display'),
      '#description' => t('Advanced users of views may choose to see the master (i.e. default) display.'),
46
      '#default_value' => $config->get('ui.show.master_display'),
47
48
49
50
51
52
    );

    $form['basic']['ui_show_advanced_column'] = array(
      '#type' => 'checkbox',
      '#title' => t('Always show advanced display settings'),
      '#description' => t('Default to showing advanced display settings, such as relationships and contextual filters.'),
53
      '#default_value' => $config->get('ui.show.advanced_column'),
54
55
56
57
58
    );

    $form['basic']['ui_show_display_embed'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show the embed display in the ui.'),
59
      '#description' => t("Allow advanced user to use the embed view display. The plugin itself works if it's not visible in the ui"),
60
      '#default_value' => $config->get('ui.show.display_embed'),
61
62
63
64
65
66
    );

    $form['basic']['ui_exposed_filter_any_label'] = array(
      '#type' => 'select',
      '#title' => t('Label for "Any" value on non-required single-select exposed filters'),
      '#options' => array('old_any' => '<Any>', 'new_any' => t('- Any -')),
67
      '#default_value' => $config->get('ui.exposed_filter_any_label'),
68
69
70
71
72
73
74
75
76
77
    );

    $form['live_preview'] = array(
      '#type' => 'details',
      '#title' => t('Live preview settings'),
    );

    $form['live_preview']['ui_always_live_preview'] = array(
      '#type' => 'checkbox',
      '#title' => t('Automatically update preview on changes'),
78
      '#default_value' => $config->get('ui.always_live_preview'),
79
80
81
82
83
    );

    $form['live_preview']['ui_show_preview_information'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show information and statistics about the view during live preview'),
84
      '#default_value' => $config->get('ui.show.preview_information'),
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    );

    $form['live_preview']['options'] = array(
      '#type' => 'container',
      '#states' => array(
        'visible' => array(
          ':input[name="ui_show_preview_information"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['live_preview']['options']['ui_show_sql_query_where'] = array(
      '#type' => 'radios',
      '#options' => array(
        'above' => t('Above the preview'),
        'below' => t('Below the preview'),
      ),
102
      '#default_value' => $config->get('ui.show.sql_query.where'),
103
104
105
106
107
    );

    $form['live_preview']['options']['ui_show_sql_query_enabled'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show the SQL query'),
108
      '#default_value' => $config->get('ui.show.sql_query.enabled'),
109
110
111
112
    );
    $form['live_preview']['options']['ui_show_performance_statistics'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show performance statistics'),
113
      '#default_value' => $config->get('ui.show.performance_statistics'),
114
115
116
117
118
119
    );

    $form['live_preview']['options']['ui_show_additional_queries'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show other queries run during render during live preview'),
      '#description' => 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."),
120
      '#default_value' => $config->get('ui.show.additional_queries'),
121
122
    );

123
    return $form;
124
125
126
127
128
129
  }

  /**
   * Implements \Drupal\Core\Form\FormInterface::submitForm().
   */
  public function submitForm(array &$form, array &$form_state) {
130
    $this->configFactory->get('views.settings')
131
132
133
134
135
136
137
138
139
140
141
142
143
144
      ->set('ui.show.master_display', $form_state['values']['ui_show_master_display'])
      ->set('ui.show.advanced_column', $form_state['values']['ui_show_advanced_column'])
      ->set('ui.show.display_embed', $form_state['values']['ui_show_display_embed'])
      ->set('ui.exposed_filter_any_label', $form_state['values']['ui_exposed_filter_any_label'])
      ->set('ui.always_live_preview', $form_state['values']['ui_always_live_preview'])
      ->set('ui.show.preview_information', $form_state['values']['ui_show_preview_information'])
      ->set('ui.show.sql_query.where', $form_state['values']['ui_show_sql_query_where'])
      ->set('ui.show.sql_query.enabled', $form_state['values']['ui_show_sql_query_enabled'])
      ->set('ui.show.performance_statistics', $form_state['values']['ui_show_performance_statistics'])
      ->set('ui.show.additional_queries', $form_state['values']['ui_show_additional_queries'])
      ->save();
  }

}