3 namespace Drupal\views_ui\Form;
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;
12 * Form builder for the admin display defaults page.
16 class BasicSettingsForm extends ConfigFormBase {
21 * @var \Drupal\Core\Extension\ThemeHandlerInterface
23 protected $themeHandler;
26 * Constructs a \Drupal\views_ui\Form\BasicSettingsForm object.
28 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
29 * The factory for configuration objects.
30 * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
33 public function __construct(ConfigFactoryInterface $config_factory, ThemeHandlerInterface $theme_handler) {
34 parent::__construct($config_factory);
36 $this->themeHandler = $theme_handler;
42 public static function create(ContainerInterface $container) {
44 $container->get('config.factory'),
45 $container->get('theme_handler')
52 public function getFormId() {
53 return 'views_ui_admin_settings_basic';
59 protected function getEditableConfigNames() {
60 return ['views.settings'];
66 public function buildForm(array $form, FormStateInterface $form_state) {
67 $form = parent::buildForm($form, $form_state);
69 $config = $this->config('views.settings');
71 foreach ($this->themeHandler->listInfo() as $name => $theme) {
73 $options[$name] = $theme->info['name'];
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.
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'),
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'),
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'),
100 $form['basic']['ui_exposed_filter_any_label'] = [
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'),
107 $form['live_preview'] = [
108 '#type' => 'details',
109 '#title' => $this->t('Live preview settings'),
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'),
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'),
125 $form['live_preview']['options'] = [
126 '#type' => 'container',
129 ':input[name="ui_show_preview_information"]' => ['checked' => TRUE],
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'),
140 $form['live_preview']['options']['ui_show_sql_query_where'] = [
144 ':input[name="ui_show_sql_query_enabled"]' => ['checked' => TRUE],
147 '#title' => t('Show SQL query'),
149 'above' => $this->t('Above the preview'),
150 'below' => $this->t('Below the preview'),
152 '#default_value' => $config->get('ui.show.sql_query.where'),
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'),
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'),
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'))
188 parent::submitForm($form, $form_state);