diff --git a/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php index b415a70..967ab01 100644 --- a/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php +++ b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php @@ -8,11 +8,40 @@ namespace Drupal\system; use Drupal\Core\Form\FormInterface; +use Drupal\Core\ControllerInterface; +use Drupal\Core\Config\ConfigFactory; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for implementing system configuration forms. */ -abstract class SystemConfigFormBase implements FormInterface { +abstract class SystemConfigFormBase implements FormInterface, ControllerInterface { + + /** + * Stores the configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** + * Constructs a \Drupal\system\SystemConfigFormBase object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + */ + public function __construct(ConfigFactory $config_factory) { + $this->configFactory = $config_factory; + } + + /** + * Implements \Drupal\Core\ControllerInterface::create(). + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory') + ); + } /** * Implements \Drupal\Core\Form\FormInterface::buildForm(). diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/AdvancedSettingsForm.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/AdvancedSettingsForm.php index 3be09d4..c638cf3 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/AdvancedSettingsForm.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/AdvancedSettingsForm.php @@ -7,10 +7,12 @@ namespace Drupal\views_ui\Form; +use Drupal\system\SystemConfigFormBase; + /** * Form builder for the advanced admin settings page. */ -class AdvancedSettingsForm extends SettingsFormBase { +class AdvancedSettingsForm extends SystemConfigFormBase { /** * Implements \Drupal\Core\Form\FormInterface::getFormID(). @@ -25,6 +27,7 @@ public function getFormID() { public function buildForm(array $form, array &$form_state) { $form = parent::buildForm($form, $form_state); + $config = $this->configFactory->get('views.settings'); $form['cache'] = array( '#type' => 'details', '#title' => t('Caching'), @@ -34,7 +37,7 @@ public function buildForm(array $form, array &$form_state) { '#type' => 'checkbox', '#title' => t('Disable views data caching'), '#description' => 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."), - '#default_value' => $this->config->get('skip_cache'), + '#default_value' => $config->get('skip_cache'), ); $form['cache']['clear_cache'] = array( @@ -53,14 +56,14 @@ public function buildForm(array $form, array &$form_state) { '#title' => t('Add Views signature to all SQL queries'), '#description' => 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."), - '#default_value' => $this->config->get('sql_signature'), + '#default_value' => $config->get('sql_signature'), ); $form['debug']['no_javascript'] = array( '#type' => 'checkbox', '#title' => t('Disable JavaScript with Views'), '#description' => t("If you are having problems with the JavaScript, you can disable it here. The Views UI should degrade and still be usable without javascript; it's just not as good."), - '#default_value' => $this->config->get('no_javascript'), + '#default_value' => $config->get('no_javascript'), ); $options = views_fetch_plugin_names('display_extender'); @@ -70,7 +73,7 @@ public function buildForm(array $form, array &$form_state) { ); $form['extenders']['display_extenders'] = array( '#title' => t('Display extenders'), - '#default_value' => array_filter($this->config->get('display_extenders')), + '#default_value' => array_filter($config->get('display_extenders')), '#options' => $options, '#type' => 'checkboxes', '#description' => t('Select extensions of the views interface.') @@ -84,7 +87,7 @@ public function buildForm(array $form, array &$form_state) { * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ public function submitForm(array &$form, array &$form_state) { - $this->config + $this->configFactory->get('views.settings') ->set('skip_cache', $form_state['values']['skip_cache']) ->set('sql_signature', $form_state['values']['sql_signature']) ->set('no_javascript', $form_state['values']['no_javascript']) diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php index 082eaa3..9631e38 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/BasicSettingsForm.php @@ -7,10 +7,12 @@ namespace Drupal\views_ui\Form; +use Drupal\system\SystemConfigFormBase; + /** * Form builder for the admin display defaults page. */ -class BasicSettingsForm extends SettingsFormBase { +class BasicSettingsForm extends SystemConfigFormBase { /** * Implements \Drupal\Core\Form\FormInterface::getFormID(). @@ -25,6 +27,7 @@ public function getFormID() { public function buildForm(array $form, array &$form_state) { $form = parent::buildForm($form, $form_state); + $config = $this->configFactory->get('views.settings'); $options = array(); foreach (list_themes() as $name => $theme) { if ($theme->status) { @@ -40,28 +43,28 @@ public function buildForm(array $form, array &$form_state) { '#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.'), - '#default_value' => $this->config->get('ui.show.master_display'), + '#default_value' => $config->get('ui.show.master_display'), ); $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.'), - '#default_value' => $this->config->get('ui.show.advanced_column'), + '#default_value' => $config->get('ui.show.advanced_column'), ); $form['basic']['ui_show_display_embed'] = array( '#type' => 'checkbox', '#title' => t('Show the embed display in the ui.'), '#description' => t('Allow advanced user to use the embed view display. The plugin itself works if it\'s not visible in the ui'), - '#default_value' => $this->config->get('ui.show.display_embed'), + '#default_value' => $config->get('ui.show.display_embed'), ); $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' => '', 'new_any' => t('- Any -')), - '#default_value' => $this->config->get('ui.exposed_filter_any_label'), + '#default_value' => $config->get('ui.exposed_filter_any_label'), ); $form['live_preview'] = array( @@ -72,13 +75,13 @@ public function buildForm(array $form, array &$form_state) { $form['live_preview']['ui_always_live_preview'] = array( '#type' => 'checkbox', '#title' => t('Automatically update preview on changes'), - '#default_value' => $this->config->get('ui.always_live_preview'), + '#default_value' => $config->get('ui.always_live_preview'), ); $form['live_preview']['ui_show_preview_information'] = array( '#type' => 'checkbox', '#title' => t('Show information and statistics about the view during live preview'), - '#default_value' => $this->config->get('ui.show.preview_information'), + '#default_value' => $config->get('ui.show.preview_information'), ); $form['live_preview']['options'] = array( @@ -96,25 +99,25 @@ public function buildForm(array $form, array &$form_state) { 'above' => t('Above the preview'), 'below' => t('Below the preview'), ), - '#default_value' => $this->config->get('ui.show.sql_query.where'), + '#default_value' => $config->get('ui.show.sql_query.where'), ); $form['live_preview']['options']['ui_show_sql_query_enabled'] = array( '#type' => 'checkbox', '#title' => t('Show the SQL query'), - '#default_value' => $this->config->get('ui.show.sql_query.enabled'), + '#default_value' => $config->get('ui.show.sql_query.enabled'), ); $form['live_preview']['options']['ui_show_performance_statistics'] = array( '#type' => 'checkbox', '#title' => t('Show performance statistics'), - '#default_value' => $this->config->get('ui.show.performance_statistics'), + '#default_value' => $config->get('ui.show.performance_statistics'), ); $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."), - '#default_value' => $this->config->get('ui.show.additional_queries'), + '#default_value' => $config->get('ui.show.additional_queries'), ); return $form; @@ -124,7 +127,7 @@ public function buildForm(array $form, array &$form_state) { * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ public function submitForm(array &$form, array &$form_state) { - $this->config + $this->configFactory->get('views.settings') ->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']) diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php deleted file mode 100644 index 662e00d..0000000 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/SettingsFormBase.php +++ /dev/null @@ -1,47 +0,0 @@ -config = $config_factory->get('views.settings'); - } - - /** - * Implements \Drupal\Core\ControllerInterface::create(). - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory') - ); - } - -}