Issue #2239065 by tim.plunkett | webchick: Overridden config bleeding through to configuration forms.

8.0.x
Alex Pott 2014-04-30 08:00:07 +01:00
parent 4ebc62247c
commit def57073bc
37 changed files with 169 additions and 210 deletions

View File

@ -16,13 +16,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
abstract class ConfigFormBase extends FormBase {
/**
* Stores the configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a \Drupal\system\ConfigFormBase object.
*
@ -30,7 +23,7 @@ abstract class ConfigFormBase extends FormBase {
* The factory for configuration objects.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
$this->setConfigFactory($config_factory);
}
/**
@ -74,10 +67,12 @@ abstract class ConfigFormBase extends FormBase {
* configuration.
*/
protected function config($name) {
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$config = $this->configFactory->get($name);
$this->configFactory->setOverrideState($old_state);
$config_factory = $this->configFactory();
$old_state = $config_factory->getOverrideState();
$config_factory->setOverrideState(FALSE);
$config = $config_factory->get($name);
$config_factory->setOverrideState($old_state);
return $config;
}
}

View File

@ -44,9 +44,14 @@ abstract class FormBase extends DependencySerialization implements FormInterface
/**
* The config factory.
*
* This is marked private in order to force subclasses to use the
* self::config() method, which may be overridden to address specific needs
* when loading config. See \Drupal\Core\Form\ConfigFormBase::config() for an
* example of this.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
private $configFactory;
/**
* The form error handler.
@ -121,10 +126,22 @@ abstract class FormBase extends DependencySerialization implements FormInterface
* A configuration object.
*/
protected function config($name) {
return $this->configFactory()->get($name);
}
/**
* Gets the config factory for this form.
*
* When accessing configuration values, use $this->config(). Only use this
* when the config factory needs to be manipulated directly.
*
* @return \Drupal\Core\Config\ConfigFactoryInterface
*/
protected function configFactory() {
if (!$this->configFactory) {
$this->configFactory = $this->container()->get('config.factory');
}
return $this->configFactory->get($name);
return $this->configFactory;
}
/**

View File

@ -99,7 +99,7 @@ class SettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('aggregator.settings');
$config = $this->config('aggregator.settings');
// Global aggregator settings.
$form['aggregator_allowed_html_tags'] = array(
@ -200,7 +200,7 @@ class SettingsForm extends ConfigFormBase {
*/
public function submitForm(array &$form, array &$form_state) {
parent::submitForm($form, $form_state);
$config = $this->configFactory->get('aggregator.settings');
$config = $this->config('aggregator.settings');
// Let active plugins save their settings.
foreach ($this->configurableInstances as $instance) {
$instance->submitConfigurationForm($form, $form_state);

View File

@ -8,7 +8,6 @@
namespace Drupal\block;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\Language;
@ -42,13 +41,6 @@ class BlockForm extends EntityForm {
*/
protected $languageManager;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a BlockForm object.
*
@ -56,13 +48,10 @@ class BlockForm extends EntityForm {
* The entity manager.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory) {
public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
$this->storage = $entity_manager->getStorage('block');
$this->languageManager = $language_manager;
$this->configFactory = $config_factory;
}
/**
@ -71,8 +60,7 @@ class BlockForm extends EntityForm {
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('language_manager'),
$container->get('config.factory')
$container->get('language_manager')
);
}
@ -84,7 +72,7 @@ class BlockForm extends EntityForm {
// Store theme settings in $form_state for use below.
if (!$theme = $entity->get('theme')) {
$theme = $this->configFactory->get('system.theme')->get('default');
$theme = $this->config('system.theme')->get('default');
}
$form_state['block_theme'] = $theme;

View File

@ -26,7 +26,7 @@ class BookSettingsForm extends ConfigFormBase {
*/
public function buildForm(array $form, array &$form_state) {
$types = node_type_get_names();
$config = $this->configFactory->get('book.settings');
$config = $this->config('book.settings');
$form['book_allowed_types'] = array(
'#type' => 'checkboxes',
'#title' => $this->t('Content types allowed in book outlines'),
@ -68,7 +68,7 @@ class BookSettingsForm extends ConfigFormBase {
// that we can save them in the correct order if node type changes.
// @see book_node_type_update().
sort($allowed_types);
$this->configFactory->get('book.settings')
$this->config('book.settings')
// Remove unchecked types.
->set('allowed_types', $allowed_types)
->set('child_type', $form_state['values']['book_child_type'])

View File

@ -0,0 +1,63 @@
<?php
/**
* @file
* Contains \Drupal\config\Tests\ConfigFormOverrideTest.
*/
namespace Drupal\config\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests config overrides do not appear on forms that extend ConfigFormBase.
*
* @see \Drupal\Core\Form\ConfigFormBase
*/
class ConfigFormOverrideTest extends WebTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Config form overrides',
'description' => 'Tests config overrides do not appear on forms that extend ConfigFormBase.',
'group' => 'Configuration',
);
}
/**
* Tests that overrides do not affect forms.
*/
public function testFormsWithOverrides() {
$this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'administer site configuration')));
$overridden_name = 'Site name global conf override';
// Set up an override.
$settings['config']['system.site']['name'] = (object) array(
'value' => $overridden_name,
'required' => TRUE,
);
$this->writeSettings($settings);
\Drupal::configFactory()->setOverrideState(TRUE);
// Test that everything on the form is the same, but that the override
// worked for the actual site name.
$this->drupalGet('admin/config/system/site-information');
$this->assertTitle('Site information | ' . $overridden_name);
$elements = $this->xpath('//input[@name="site_name"]');
$this->assertIdentical((string) $elements[0]['value'], 'Drupal');
// Submit the form and ensure the site name is not changed.
$edit = array(
'site_name' => 'Custom site name',
);
$this->drupalPostForm('admin/config/system/site-information', $edit, t('Save configuration'));
$this->assertTitle('Site information | ' . $overridden_name);
$elements = $this->xpath('//input[@name="site_name"]');
$this->assertIdentical((string) $elements[0]['value'], $edit['site_name']);
}
}

View File

@ -9,7 +9,6 @@ namespace Drupal\config_translation\Form;
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\Schema\Element;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
@ -101,15 +100,12 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
* The translation storage object.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook.
* @param \Drupal\Core\Config\ConfigFactoryInterface
* The config factory.
*/
public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager) {
public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager) {
$this->typedConfigManager = $typed_config_manager;
$this->configMapperManager = $config_mapper_manager;
$this->localeStorage = $locale_storage;
$this->moduleHandler = $module_handler;
$this->configFactory = $config_factory;
$this->languageManager = $language_manager;
}
@ -122,7 +118,6 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
$container->get('plugin.manager.config_translation.mapper'),
$container->get('locale.storage'),
$container->get('module_handler'),
$container->get('config.factory'),
$container->get('language_manager')
);
}
@ -176,10 +171,11 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
// Get base language configuration to display in the form before setting the
// language to use for the form. This avoids repetitively settings and
// resetting the language to get original values later.
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$config_factory = $this->configFactory();
$old_state = $config_factory->getOverrideState();
$config_factory->setOverrideState(FALSE);
$this->baseConfigData = $this->mapper->getConfigData();
$this->configFactory->setOverrideState($old_state);
$config_factory->setOverrideState($old_state);
// Set the translation target language on the configuration factory.
$original_language = $this->languageManager->getConfigOverrideLanguage();
@ -198,7 +194,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
);
foreach ($this->mapper->getConfigNames() as $name) {
$form['config_names'][$name] = array('#type' => 'container');
$form['config_names'][$name] += $this->buildConfigForm($this->typedConfigManager->get($name), $this->config($name)->get(), $this->baseConfigData[$name]);
$form['config_names'][$name] += $this->buildConfigForm($this->typedConfigManager->get($name), $config_factory->get($name)->get(), $this->baseConfigData[$name]);
}
$form['actions']['#type'] = 'actions';
@ -221,12 +217,13 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
$form_values = $form_state['values']['config_names'];
// For the form submission handling, use the raw data.
$old_state = $this->configFactory->getOverrideState();
$this->configFactory->setOverrideState(FALSE);
$config_factory = $this->configFactory();
$old_state = $config_factory->getOverrideState();
$config_factory->setOverrideState(FALSE);
foreach ($this->mapper->getConfigNames() as $name) {
// Set configuration values based on form submission and source values.
$base_config = $this->config($name);
$base_config = $config_factory->get($name);
$config_translation = $this->languageManager->getLanguageConfigOverride($this->language->id, $name);
$locations = $this->localeStorage->getLocations(array('type' => 'configuration', 'name' => $name));
@ -241,7 +238,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
$config_translation->save();
}
}
$this->configFactory->setOverrideState($old_state);
$config_factory->setOverrideState($old_state);
$form_state['redirect_route'] = array(
'route_name' => $this->mapper->getOverviewRoute(),

View File

@ -8,7 +8,6 @@
namespace Drupal\contact;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Flood\FloodInterface;
@ -28,13 +27,6 @@ class MessageForm extends ContentEntityForm {
*/
protected $entity;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The flood control mechanism.
*
@ -45,17 +37,14 @@ class MessageForm extends ContentEntityForm {
/**
* Constructs a MessageForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Flood\FloodInterface $flood
* The flood control mechanism.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, FloodInterface $flood) {
public function __construct(EntityManagerInterface $entity_manager, FloodInterface $flood) {
parent::__construct($entity_manager);
$this->configFactory = $config_factory;
$this->flood = $flood;
}
@ -64,7 +53,6 @@ class MessageForm extends ContentEntityForm {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity.manager'),
$container->get('flood')
);
@ -241,7 +229,7 @@ class MessageForm extends ContentEntityForm {
drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params);
}
$config = $this->configFactory->get('contact.settings');
$config = $this->config('contact.settings');
$this->flood->register('contact', $config->get('flood.interval'));
if (!$message->isPersonal()) {
watchdog('contact', '%sender-name (@sender-from) sent an e-mail regarding %category.', array(

View File

@ -18,13 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
abstract class FilterFormatFormBase extends EntityForm {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The entity query factory.
*
@ -35,13 +28,10 @@ abstract class FilterFormatFormBase extends EntityForm {
/**
* Constructs a new FilterFormatFormBase.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
*/
public function __construct(ConfigFactoryInterface $config_factory, QueryFactory $query_factory) {
$this->configFactory = $config_factory;
public function __construct(QueryFactory $query_factory) {
$this->queryFactory = $query_factory;
}
@ -50,7 +40,6 @@ abstract class FilterFormatFormBase extends EntityForm {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity.query')
);
}
@ -60,7 +49,7 @@ abstract class FilterFormatFormBase extends EntityForm {
*/
public function form(array $form, array &$form_state) {
$format = $this->entity;
$is_fallback = ($format->id() == $this->configFactory->get('filter.settings')->get('fallback_format'));
$is_fallback = ($format->id() == $this->config('filter.settings')->get('fallback_format'));
$form['#tree'] = TRUE;
$form['#attached']['library'][] = 'filter/drupal.filter.admin';
@ -100,7 +89,7 @@ abstract class FilterFormatFormBase extends EntityForm {
// If editing an existing text format, pre-select its current permissions.
$form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($format));
}
elseif ($admin_role = $this->configFactory->get('user.settings')->get('admin_role')) {
elseif ($admin_role = $this->config('user.settings')->get('admin_role')) {
// If adding a new text format and the site has an administrative role,
// pre-select that role so as to grant administrators access to the new
// text format permission by default.

View File

@ -139,7 +139,7 @@ class ForumForm extends TermForm {
$parent = 0;
}
$vid = $this->configFactory->get('forum.settings')->get('vocabulary');
$vid = $this->config('forum.settings')->get('vocabulary');
// @todo Inject a taxonomy service when one exists.
$children = taxonomy_get_tree($vid, $tid, NULL, TRUE);

View File

@ -25,7 +25,7 @@ class ForumSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('forum.settings');
$config = $this->config('forum.settings');
$options = array(5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 80, 100, 150, 200, 250, 300, 350, 400, 500);
$form['forum_hot_topic'] = array(
@ -64,7 +64,7 @@ class ForumSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('forum.settings')
$this->config('forum.settings')
->set('topics.hot_threshold', $form_state['values']['forum_hot_topic'])
->set('topics.page_limit', $form_state['values']['forum_per_page'])
->set('topics.order', $form_state['values']['forum_order'])

View File

@ -160,7 +160,7 @@ class ContentLanguageSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$config = $this->configFactory->get('language.settings');
$config = $this->config('language.settings');
foreach ($form_state['values']['settings'] as $entity_type => $entity_settings) {
foreach ($entity_settings as $bundle => $bundle_settings) {
$config->set(language_get_default_configuration_settings_key($entity_type, $bundle),

View File

@ -171,7 +171,7 @@ class NegotiationBrowserForm extends ConfigFormBase {
public function submitForm(array &$form, array &$form_state) {
$mappings = $form_state['mappings'];
if (!empty($mappings)) {
$config = $this->configFactory->get('language.mappings');
$config = $this->config('language.mappings');
$config->setData($mappings);
$config->save();
}
@ -187,7 +187,7 @@ class NegotiationBrowserForm extends ConfigFormBase {
* The browser's langcode mapping configuration array.
*/
protected function language_get_browser_drupal_langcode_mappings() {
$config = $this->configFactory->get('language.mappings');
$config = $this->config('language.mappings');
if ($config->isNew()) {
return array();
}

View File

@ -26,7 +26,7 @@ class NegotiationSelectedForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('language.negotiation');
$config = $this->config('language.negotiation');
$form['selected_langcode'] = array(
'#type' => 'language_select',
'#title' => t('Language'),
@ -41,7 +41,7 @@ class NegotiationSelectedForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('language.negotiation')
$this->config('language.negotiation')
->set('selected_langcode', $form_state['values']['selected_langcode'])
->save();

View File

@ -25,7 +25,7 @@ class NegotiationSessionForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('language.negotiation');
$config = $this->config('language.negotiation');
$form['language_negotiation_session_param'] = array(
'#title' => t('Request/session parameter'),
'#type' => 'textfield',
@ -42,7 +42,7 @@ class NegotiationSessionForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('language.settings')
$this->config('language.settings')
->set('session.parameter', $form_state['values']['language_negotiation_session_param'])
->save();

View File

@ -27,7 +27,7 @@ class NegotiationUrlForm extends ConfigFormBase {
*/
public function buildForm(array $form, array &$form_state) {
global $base_url;
$config = $this->configFactory->get('language.negotiation');
$config = $this->config('language.negotiation');
$form['language_negotiation_url_part'] = array(
'#title' => t('Part of the URL that determines language'),
@ -162,7 +162,7 @@ class NegotiationUrlForm extends ConfigFormBase {
*/
public function submitForm(array &$form, array &$form_state) {
// Save selected format (prefix or domain).
$this->configFactory->get('language.negotiation')
$this->config('language.negotiation')
->set('url.source', $form_state['values']['language_negotiation_url_part'])
->save();

View File

@ -24,7 +24,7 @@ class LocaleSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('locale.settings');
$config = $this->config('locale.settings');
$form['update_interval_days'] = array(
'#type' => 'radios',
@ -97,7 +97,7 @@ class LocaleSettingsForm extends ConfigFormBase {
public function submitForm(array &$form, array &$form_state) {
$values = $form_state['values'];
$config = $this->configFactory->get('locale.settings');
$config = $this->config('locale.settings');
$config->set('translation.update_interval_days', $values['update_interval_days'])->save();
$config->set('translation.use_source', $values['use_source'])->save();

View File

@ -25,7 +25,7 @@ class MenuSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('menu_ui.settings');
$config = $this->config('menu_ui.settings');
$form['intro'] = array(
'#type' => 'item',
'#markup' => t('The Menu UI module allows on-the-fly creation of menu links in the content authoring forms. To configure these settings for a particular content type, visit the <a href="@content-types">Content types</a> page, click the <em>edit</em> link for the content type, and go to the <em>Menu settings</em> section.', array('@content-types' => url('admin/structure/types'))),
@ -61,7 +61,7 @@ class MenuSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('menu_ui.settings')
$this->config('menu_ui.settings')
->set('main_links', $form_state['values']['menu_main_links_source'])
->set('secondary_links', $form_state['values']['menu_secondary_links_source'])
->save();

View File

@ -25,7 +25,7 @@ class SimpletestSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('simpletest.settings');
$config = $this->config('simpletest.settings');
$form['general'] = array(
'#type' => 'details',
'#title' => $this->t('General'),
@ -87,7 +87,7 @@ class SimpletestSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
$config = $this->configFactory->get('simpletest.settings');
$config = $this->config('simpletest.settings');
// If a username was provided but a password wasn't, preserve the existing
// password.
if (!empty($form_state['values']['simpletest_httpauth_username']) && empty($form_state['values']['simpletest_httpauth_password'])) {
@ -107,7 +107,7 @@ class SimpletestSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('simpletest.settings')
$this->config('simpletest.settings')
->set('clear_results', $form_state['values']['simpletest_clear_results'])
->set('verbose', $form_state['values']['simpletest_verbose'])
->set('httpauth.method', $form_state['values']['simpletest_httpauth_method'])

View File

@ -58,7 +58,7 @@ class StatisticsSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('statistics.settings');
$config = $this->config('statistics.settings');
// Content counter settings.
$form['content'] = array(
@ -80,7 +80,7 @@ class StatisticsSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('statistics.settings')
$this->config('statistics.settings')
->set('count_content_views', $form_state['values']['statistics_count_content_views'])
->save();

View File

@ -71,7 +71,7 @@ class CronForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('system.cron');
$config = $this->config('system.cron');
$form['description'] = array(
'#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>',
@ -112,7 +112,7 @@ class CronForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.cron')
$this->config('system.cron')
->set('threshold.autorun', $form_state['values']['cron_safe_threshold'])
->save();

View File

@ -26,7 +26,7 @@ class FileSystemForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('system.file');
$config = $this->config('system.file');
$form['file_public_path'] = array(
'#type' => 'item',
'#title' => t('Public file system path'),
@ -86,7 +86,7 @@ class FileSystemForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$config = $this->configFactory->get('system.file')
$config = $this->config('system.file')
->set('path.private', $form_state['values']['file_private_path'])
->set('path.temporary', $form_state['values']['file_temporary_path'])
->set('temporary_maximum_age', $form_state['values']['temporary_maximum_age']);

View File

@ -61,7 +61,7 @@ class ImageToolkitForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$current_toolkit = $this->configFactory->get('system.image')->get('toolkit');
$current_toolkit = $this->config('system.image')->get('toolkit');
$form['image_toolkit'] = array(
'#type' => 'radios',
@ -96,7 +96,7 @@ class ImageToolkitForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.image')
$this->config('system.image')
->set('toolkit', $form_state['values']['image_toolkit'])
->save();

View File

@ -25,7 +25,7 @@ class LoggingForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('system.logging');
$config = $this->config('system.logging');
$form['error_level'] = array(
'#type' => 'radios',
'#title' => t('Error messages to display'),
@ -46,7 +46,7 @@ class LoggingForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.logging')
$this->config('system.logging')
->set('error_level', $form_state['values']['error_level'])
->save();

View File

@ -60,7 +60,7 @@ class PerformanceForm extends ConfigFormBase {
public function buildForm(array $form, array &$form_state) {
$form['#attached']['library'][] = 'system/drupal.system';
$config = $this->configFactory->get('system.performance');
$config = $this->config('system.performance');
$form['clear_cache'] = array(
'#type' => 'details',
@ -152,7 +152,7 @@ class PerformanceForm extends ConfigFormBase {
// form submit.
$this->renderCache->deleteAll();
$this->configFactory->get('system.performance')
$this->config('system.performance')
->set('cache.page.use_internal', $form_state['values']['cache'])
->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age'])
->set('response.gzip', $form_state['values']['page_compression'])

View File

@ -59,7 +59,7 @@ class RegionalForm extends ConfigFormBase {
*/
public function buildForm(array $form, array &$form_state) {
$countries = $this->countryManager->getList();
$system_date = $this->configFactory->get('system.date');
$system_date = $this->config('system.date');
// Date settings:
$zones = system_time_zones();
@ -142,7 +142,7 @@ class RegionalForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.date')
$this->config('system.date')
->set('country.default', $form_state['values']['site_default_country'])
->set('first_day', $form_state['values']['date_first_day'])
->set('timezone.default', $form_state['values']['date_default_timezone'])

View File

@ -25,7 +25,7 @@ class RssFeedsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$rss_config = $this->configFactory->get('system.rss');
$rss_config = $this->config('system.rss');
$form['feed_description'] = array(
'#type' => 'textarea',
'#title' => t('Feed description'),
@ -59,7 +59,7 @@ class RssFeedsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.rss')
$this->config('system.rss')
->set('channel.description', $form_state['values']['feed_description'])
->set('items.limit', $form_state['values']['feed_default_items'])
->set('items.view_mode', $form_state['values']['feed_item_length'])

View File

@ -59,7 +59,7 @@ class SiteInformationForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$site_config = $this->configFactory->get('system.site');
$site_config = $this->config('system.site');
$site_mail = $site_config->get('mail');
if (empty($site_mail)) {
$site_mail = ini_get('sendmail_from');
@ -168,7 +168,7 @@ class SiteInformationForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.site')
$this->config('system.site')
->set('name', $form_state['values']['site_name'])
->set('mail', $form_state['values']['site_mail'])
->set('slogan', $form_state['values']['site_slogan'])

View File

@ -57,7 +57,7 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('system.maintenance');
$config = $this->config('system.maintenance');
$form['maintenance_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Put site into maintenance mode'),
@ -77,7 +77,7 @@ class SiteMaintenanceModeForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('system.maintenance')
$this->config('system.maintenance')
->set('message', $form_state['values']['maintenance_mode_message'])
->save();

View File

@ -376,7 +376,7 @@ class ThemeSettingsForm extends ConfigFormBase {
public function submitForm(array &$form, array &$form_state) {
parent::submitForm($form, $form_state);
$config = $this->configFactory->get($form_state['values']['config_key']);
$config = $this->config($form_state['values']['config_key']);
// Exclude unnecessary elements before saving.
form_state_values_clean($form_state);

View File

@ -8,47 +8,14 @@
namespace Drupal\taxonomy;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\Language;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base for controller for taxonomy term edit forms.
*/
class TermForm extends ContentEntityForm {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a new TermForm.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($entity_manager);
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
@ -81,7 +48,7 @@ class TermForm extends ContentEntityForm {
// numbers of items so we check for taxonomy.settings:override_selector
// before loading the full vocabulary. Contrib modules can then intercept
// before hook_form_alter to provide scalable alternatives.
if (!$this->configFactory->get('taxonomy.settings')->get('override_selector')) {
if (!$this->config('taxonomy.settings')->get('override_selector')) {
$parent = array_keys(taxonomy_term_load_parents($term->id()));
$children = taxonomy_get_tree($vocabulary->id(), $term->id());

View File

@ -25,7 +25,7 @@ class UpdateSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('update.settings');
$config = $this->config('update.settings');
$form['update_check_frequency'] = array(
'#type' => 'radios',
@ -104,7 +104,7 @@ class UpdateSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$config = $this->configFactory->get('update.settings');
$config = $this->config('update.settings');
// See if the update_check_disabled setting is being changed, and if so,
// invalidate all update status data.
if ($form_state['values']['update_check_disabled'] != $config->get('check.disabled_extensions')) {

View File

@ -59,9 +59,9 @@ class AccountSettingsForm extends ConfigFormBase {
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state) {
$config = $this->configFactory->get('user.settings');
$mail_config = $this->configFactory->get('user.mail');
$site_config = $this->configFactory->get('system.site');
$config = $this->config('user.settings');
$mail_config = $this->config('user.mail');
$site_config = $this->config('system.site');
// Settings for anonymous users.
$form['anonymous_settings'] = array(
@ -410,7 +410,7 @@ class AccountSettingsForm extends ConfigFormBase {
public function submitForm(array &$form, array &$form_state) {
parent::submitForm($form, $form_state);
$this->configFactory->get('user.settings')
$this->config('user.settings')
->set('anonymous', $form_state['values']['anonymous'])
->set('admin_role', $form_state['values']['user_admin_role'])
->set('register', $form_state['values']['user_register'])
@ -422,7 +422,7 @@ class AccountSettingsForm extends ConfigFormBase {
->set('notify.status_blocked', $form_state['values']['user_mail_status_blocked_notify'])
->set('notify.status_canceled', $form_state['values']['user_mail_status_canceled_notify'])
->save();
$this->configFactory->get('user.mail')
$this->config('user.mail')
->set('cancel_confirm.body', $form_state['values']['user_mail_cancel_confirm_body'])
->set('cancel_confirm.subject', $form_state['values']['user_mail_cancel_confirm_subject'])
->set('password_reset.body', $form_state['values']['user_mail_password_reset_body'])
@ -440,7 +440,7 @@ class AccountSettingsForm extends ConfigFormBase {
->set('status_canceled.body', $form_state['values']['user_mail_status_canceled_body'])
->set('status_canceled.subject', $form_state['values']['user_mail_status_canceled_subject'])
->save();
$this->configFactory->get('system.site')
$this->config('system.site')
->set('mail_notification', $form_state['values']['mail_notification_address'])
->save();
}

View File

@ -7,10 +7,7 @@
namespace Drupal\user\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Entity\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a confirmation form for cancelling user account.
@ -24,13 +21,6 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
*/
protected $cancelMethods;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The user being cancelled.
*
@ -38,29 +28,6 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
*/
protected $entity;
/**
* Constructs an EntityForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($entity_manager);
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
@ -82,7 +49,7 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
*/
public function getDescription() {
$description = '';
$default_method = $this->configFactory->get('user.settings')->get('cancel_method');
$default_method = $this->config('user.settings')->get('cancel_method');
if ($this->currentUser()->hasPermission('administer users') || $this->currentUser()->hasPermission('select account cancellation method')) {
$description = $this->t('Select the method to cancel the account above.');
}
@ -129,7 +96,7 @@ class UserCancelForm extends ContentEntityConfirmFormBase {
'#description' => $this->t('When enabled, the user must confirm the account cancellation via e-mail.'),
);
// Also allow to send account canceled notification mail, if enabled.
$default_notify = $this->configFactory->get('user.settings')->get('notify.status_canceled');
$default_notify = $this->config('user.settings')->get('notify.status_canceled');
$form['user_cancel_notify'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Notify user when account is canceled.'),

View File

@ -8,7 +8,6 @@
namespace Drupal\user\Form;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Routing\UrlGeneratorInterface;
@ -29,13 +28,6 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
*/
protected $tempStoreFactory;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The user storage.
*
@ -55,16 +47,13 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
*
* @param \Drupal\user\TempStoreFactory $temp_store_factory
* The temp store factory.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\user\UserStorageInterface $user_storage
* The user storage.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(TempStoreFactory $temp_store_factory, ConfigFactoryInterface $config_factory, UserStorageInterface $user_storage, EntityManagerInterface $entity_manager) {
public function __construct(TempStoreFactory $temp_store_factory, UserStorageInterface $user_storage, EntityManagerInterface $entity_manager) {
$this->tempStoreFactory = $temp_store_factory;
$this->configFactory = $config_factory;
$this->userStorage = $user_storage;
$this->entityManager = $entity_manager;
}
@ -75,7 +64,6 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
public static function create(ContainerInterface $container) {
return new static(
$container->get('user.tempstore'),
$container->get('config.factory'),
$container->get('entity.manager')->getStorage('user'),
$container->get('entity.manager')
);
@ -166,7 +154,7 @@ class UserMultipleCancelConfirm extends ConfirmFormBase {
'#type' => 'checkbox',
'#title' => $this->t('Notify user when account is canceled.'),
'#default_value' => FALSE,
'#access' => $this->configFactory->get('user.settings')->get('notify.status_canceled'),
'#access' => $this->config('user.settings')->get('notify.status_canceled'),
'#description' => $this->t('When enabled, the user will receive an e-mail notification after the account has been canceled.'),
);

View File

@ -28,7 +28,7 @@ class AdvancedSettingsForm extends ConfigFormBase {
public function buildForm(array $form, array &$form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this->configFactory->get('views.settings');
$config = $this->config('views.settings');
$form['cache'] = array(
'#type' => 'details',
'#title' => $this->t('Caching'),
@ -91,7 +91,7 @@ class AdvancedSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('views.settings')
$this->config('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'])

View File

@ -27,7 +27,7 @@ class BasicSettingsForm extends ConfigFormBase {
public function buildForm(array $form, array &$form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this->configFactory->get('views.settings');
$config = $this->config('views.settings');
$options = array();
foreach (list_themes() as $name => $theme) {
if ($theme->status) {
@ -127,7 +127,7 @@ class BasicSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configFactory->get('views.settings')
$this->config('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'])