diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index d488664..7dc1685 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2225,6 +2225,7 @@ function _drupal_error_handler($error_level, $message, $filename, $line, $contex * The exception object that was thrown. */ function _drupal_exception_handler($exception) { + require_once DRUPAL_ROOT . '/core/includes/errors.inc'; try { @@ -2465,12 +2466,14 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { ->addArgument(new Reference('cache.config')); // Register configuration object factory. - $container->register('config.subscriber.globalconf', 'Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber'); + $container->register('config.subscriber.globalconf', 'Drupal\Core\EventSubscriber\ConfigOverrideSubscriber'); $container->register('dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher') ->addMethodCall('addSubscriber', array(new Reference('config.subscriber.globalconf'))); - $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') + $container->register('config.context', 'Drupal\Core\Config\Context\GlobalContext') ->addArgument(new Reference('config.storage')) ->addArgument(new Reference('dispatcher')); + $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') + ->addArgument(new Reference('config.context')); // Register staging configuration storage. $container diff --git a/core/includes/config.inc b/core/includes/config.inc index e263668..d7776e0 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -1,7 +1,7 @@ get('config.factory')->get($name)->load(); -} - -/** - * Retrieves a configuration object for administration. - * - * This configuration object will be created using a special configuration - * context (config.admin = TRUE) and configuration plug-ins should mostly keep - * hands off it and don't override it. - * - * This is intended for administration forms or any other case when we need to - * get / set the configuration data without any overrides, as oppossed to - * regular configuration used for runtime operations that may be altered by - * plug-ins depending on other page request parameters: - * - * To get regular configuration objects for the page request use config() - * instead of this function. - * - * @param $name - * The name of the configuration object to retrieve. + * @param Drupal\Core\Config\ContextInterface $context + * (optional) Configuration context to use for the configuration object. + * Defaults to the context object registered in the Drupal Container. * * @return Drupal\Core\Config\Config * A configuration object. - * - * @see config() - */ -function config_admin($name) { - static $config_factory; - if (!isset($config_factory)) { - $config_factory = config_factory(array('config.admin' => TRUE)); - } - return $config_factory->get($name)->load(); -} - -/** - * Retrieves a configuration factory object for a given context. - * - * A configuration context is an array of parameters that are available to the - * configuration plug-ins for them to customize the configuration data in - * different ways. Examples of parameters used by Drupal core are: - * - 'user.account', to get configuration that may be localized for a user. - * - 'config.admin', TRUE to get configuration data without further - * customizations for administration purposes. - * - * Modules can add any other parameter or provide plug-ins that react to - * specific context parameters. In order to avoid conflicts the parameter - * keys should be prefixed by the module name. - * - * @param array $context - * (optional) Array with contextual data to be used for the configuration - * factory. Defaults to an empty array. - * @param Drupal\Core\Config\StorageInterface $storage - * (optional) The storage controller object to use for reading and writing - * configuration data. Defaults to the storage controller object registered - * in the Drupal Container. - * @param Symfony\Component\EventDispatcher\EventDispatcher - * (optional) An event dispatcher instance to use for configuration events. - * Defaults to the event dispatcher instance registered in the Drupal - * Container. - * - * @return Drupal\Core\Config\ConfigFactory - * Configuration factory object. */ -function config_factory(array $context = array(), StorageInterface $storage = NULL, EventDispatcher $event_dispatcher = NULL) { - $storage = $storage ? $storage : drupal_container()->get('config.storage'); - $event_dispatcher = $event_dispatcher ? $event_dispatcher : drupal_container()->get('dispatcher'); - $factory = new ConfigFactory($storage, $event_dispatcher); - foreach ($context as $key => $value) { - $factory->setContext($key, $value); - } - // Notify other modules and allow them to add other context objects. - module_invoke_all('config_factory', $factory); - return $factory; +function config($name, $context = NULL) { + return drupal_container()->get('config.factory')->get($name, $context)->load(); } /** @@ -252,14 +192,16 @@ function config_sync_get_changes(StorageInterface $source_storage, StorageInterf * The storage to synchronize configuration to. */ function config_sync_changes(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { + $target_context = new AdminContext('config.target', $target_storage); foreach (array('delete', 'create', 'change') as $op) { foreach ($config_changes[$op] as $name) { + $config = new Config($name, $target_context); if ($op == 'delete') { - $target_storage->delete($name); + $config->delete(); } else { $data = $source_storage->read($name); - $target_storage->write($name, $data); + $config->setData($data)->save(); } } } @@ -318,6 +260,7 @@ function config_import() { * @todo Add support for other extension types; e.g., themes etc. */ function config_import_invoke_owner(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { + $target_context = new AdminContext('config.target', $target_storage); // Allow modules to take over configuration change operations for // higher-level configuration data. // First pass deleted, then new, and lastly changed configuration, in order to @@ -330,11 +273,11 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou // handle the configuration change. $handled_by_module = FALSE; if (module_hook($module, 'config_import_' . $op)) { - $old_config = new Config($name, $target_storage); + $old_config = new Config($name, $target_context); $old_config->load(); $data = $source_storage->read($name); - $new_config = new Config($name, $target_storage); + $new_config = new Config($name, $target_context); if ($data !== FALSE) { $new_config->setData($data); } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index d5983b6..b896a8d 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -319,9 +319,11 @@ function install_begin_request(&$install_state) { $container->register('dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher'); $container->register('config.storage', 'Drupal\Core\Config\InstallStorage'); - $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') + $container->register('config.context', 'Drupal\Core\Config\Context\ConfigContext') ->addArgument(new Reference('config.storage')) ->addArgument(new Reference('dispatcher')); + $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') + ->addArgument(new Reference('config.context')); drupal_container($container); } diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 563ae21..7021b22 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -8,8 +8,6 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Drupal\Core\Config\ConfigFactory; /** * Defines the default configuration object. @@ -52,11 +50,11 @@ class Config { protected $overriddenData; /** - * The configuration factory that produces this configuration object. + * The configuration context used for this configuration object. * - * @var Drupal\Core\Config\ConfigFactory + * @var Drupal\Core\Config\ContextInterface */ - protected $factory; + protected $context; /** * The storage used to load and save this configuration object. @@ -70,18 +68,14 @@ class Config { * * @param string $name * The name of the configuration object being constructed. - * @param Drupal\Core\Config\StorageInterface $storage + * @param Drupal\Core\Config\ContextInterface $context * A storage controller object to use for reading and writing the * configuration data. - * @param Drupal\Core\Config\ConfigFactory $factory - * (optional) A configuration factory object that produces this config - * object. Defaults to the storage controller object registered in the - * Drupal Container. */ - public function __construct($name, StorageInterface $storage, ConfigFactory $factory = NULL) { + public function __construct($name, ContextInterface $context) { $this->name = $name; - $this->storage = $storage; - $this->factory = $factory ? $factory : drupal_container()->get('config.factory'); + $this->context = $context; + $this->storage = $context->getStorage(); } /** @@ -388,25 +382,6 @@ public function delete() { return $this; } - /** - * Retrieve the storage used to load and save this configuration object. - * - * @return \Drupal\Core\Config\StorageInterface - * The configuration storage object. - */ - public function getStorage() { - return $this->storage; - } - - /** - * Retrieves the configuration factory that produces this configuration object. - * - * @return Drupal\Core\Config\ConfigFactory - * A configuration factory that produces this configuration object. - */ - public function getFactory() { - return $this->factory; - } /** * Dispatches a config event. @@ -415,7 +390,7 @@ public function getFactory() { * Event name. */ protected function notify($config_event_name) { - $this->factory->notify($config_event_name, $this); + $this->context->notify($config_event_name, $this); } /* diff --git a/core/lib/Drupal/Core/Config/ConfigEvent.php b/core/lib/Drupal/Core/Config/ConfigEvent.php index 710f51f..efe6953 100644 --- a/core/lib/Drupal/Core/Config/ConfigEvent.php +++ b/core/lib/Drupal/Core/Config/ConfigEvent.php @@ -3,9 +3,9 @@ namespace Drupal\Core\Config; use Symfony\Component\EventDispatcher\Event; -use Drupal\Core\Config\Config; class ConfigEvent extends Event { + /** * Configuration object. * @@ -14,16 +14,23 @@ class ConfigEvent extends Event { protected $config; /** + * Configuration context object. + * + * @var Drupal\Core\Config\ContextInterface + */ + protected $context; + + /** * Constructs a configuration event object. * + * @param Drupal\Core\Config\ContextInterface + * Configuration context object. * @param Drupal\Core\Config\Config - * Configuration object. - * @param Drupal\Core\Config\ConfigFactory - * Configuration factory object. + * (optional) Configuration object. */ - public function __construct(Config $config, ConfigFactory $factory) { + public function __construct(ContextInterface $context, Config $config = NULL) { $this->config = $config; - $this->factory = $factory; + $this->context = $context; } /** @@ -34,12 +41,12 @@ public function getConfig() { } /** - * Get configuration factory object. + * Get configuration context object. * - * @return Drupal\Core\Config\ConfigFactory - * Configuration factory object. + * @return Drupal\Core\Config\ContextInterface + * Configuration context. */ - public function getFactory() { - return $this->factory; + public function getContext() { + return $this->context; } } diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index a2b4b51..dec7b4e 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -25,52 +25,29 @@ class ConfigFactory { /** - * A storage controller instance for reading and writing configuration data. + * The default configuration context associated with this factory. * - * @var Drupal\Core\Config\StorageInterface + * @var Drupal\Core\Config\ContextInterface */ - protected $storage; + protected $context; - /** - * An event dispatcher instance to use for configuration events. - * - * @var Symfony\Component\EventDispatcher\EventDispatcher - */ - protected $eventDispatcher; - - /** - * The data of the configuration context. - * - * @var array - */ - protected $context; - - /** - * Constructs the Config factory. - * - * @param Drupal\Core\Config\StorageInterface $storage - * The storage controller object to use for reading and writing - * configuration data. - * @param Symfony\Component\EventDispatcher\EventDispatcher - * An event dispatcher instance to use for configuration events. - */ - public function __construct(StorageInterface $storage, EventDispatcher $event_dispatcher) { - $this->storage = $storage; - $this->eventDispatcher = $event_dispatcher; - $this->context = array(); + public function __construct(ContextInterface $context) { + $this->setContext($context); } /** - * Returns a configuration object for a given name. + * Returns a configuration object for a given name and context. * * @param string $name * The name of the configuration object to construct. * + * @param Drupal\Core\Config\ContextInterface $context + * (optional) Context to use to get the configuration + * * @return Drupal\Core\Config\Config * A configuration object with the given $name. */ - public function get($name) { - global $conf; + public function get($name, $context = NULL) { // @todo Caching the instantiated objects per name might cut off a fair // amount of CPU time and memory. Only the data within the configuration @@ -90,64 +67,28 @@ public function get($name) { // @todo The decrease of CPU time is interesting, since that means that // ContainerBuilder involves plenty of function calls (which are known to // be slow in PHP). - $config = new Config($name, $this->storage, $this); + $config = new Config($name, $context ?: $this->context); return $config->init(); } /** - * Get storage controller. + * Gets the default context for this factory. * - * @return Drupal\Core\Config\StorageInterface - * A storage controller instance for reading and writing configuration data. + * @return Drupal\Core\Config\ContextInterface + * A configuration context instance. */ - public function getStorage() { - return $this->storage; + public function getContext() { + return $this->context; } /** - * Gets data from this config context. + * Sets the default context for this factory. * - * @param string $key - * (optional) A string that maps to a key within the context data or empty - * to get all data. - * - * @return array - * The data that was requested. + * @param Drupal\Core\Config\ContextInterface $context + * Context to use to get the configuration. */ - public function getContext($key = '') { - if ($key) { - return isset($this->context[$key]) ? $this->context[$key] : NULL; - } - else { - return $this->context; - } + public function setContext($context) { + $this->context = $context; } - /** - * Sets data on this config context. - * - * @param $key - * A string that maps to a key within the configuration context. - * @param $value - * Any value to be set for this key. - * - * @return Drupal\Core\Config\ConfigFactory - * This ConfigFactory instance. - */ - public function setContext($key, $value) { - $this->context[$key] = $value; - return $this; - } - - /** - * Dispatches a config event. - * - * @param string $config_event_name - * Event name. - * @param Drupal\Core\Config\Config - * Configuration object. - */ - public function notify($config_event_name, Config $config) { - $this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($config, $this)); - } } diff --git a/core/lib/Drupal/Core/Config/Context/AdminContext.php b/core/lib/Drupal/Core/Config/Context/AdminContext.php new file mode 100644 index 0000000..b2a6c23 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Context/AdminContext.php @@ -0,0 +1,42 @@ +set(self::ADMIN, $name); + $this->set($name, TRUE); + parent::__construct($storage ?: drupal_container()->get('config.storage'), drupal_container()->get('dispatcher')); + // Notify event listeners that a configuration context has been created. + $this->notify('context', NULL); + } + +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/Config/Context/ConfigContext.php b/core/lib/Drupal/Core/Config/Context/ConfigContext.php new file mode 100644 index 0000000..f164d95 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Context/ConfigContext.php @@ -0,0 +1,89 @@ +storage = $storage; + $this->eventDispatcher = $event_dispatcher; + } + + /** + * Implements Drupal\Core\Config\ContextInterface::getStorage(). + */ + public function getStorage() { + return $this->storage; + } + + /** + * Implements Drupal\Core\Config\ContextInterface::notify(). + */ + public function notify($config_event_name, Config $config = NULL) { + $this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($this, $config)); + } + +} diff --git a/core/lib/Drupal/Core/Config/Context/GlobalContext.php b/core/lib/Drupal/Core/Config/Context/GlobalContext.php new file mode 100644 index 0000000..d7b1915 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Context/GlobalContext.php @@ -0,0 +1,32 @@ +data[self::OVERRIDE] = &$conf; + parent::__construct($storage, $event_dispatcher); + } + +} diff --git a/core/lib/Drupal/Core/Config/Context/ObjectContext.php b/core/lib/Drupal/Core/Config/Context/ObjectContext.php new file mode 100644 index 0000000..eb17e3f --- /dev/null +++ b/core/lib/Drupal/Core/Config/Context/ObjectContext.php @@ -0,0 +1,43 @@ +set(self::OBJECT, $name); + $this->set($name, $object); + parent::__construct(drupal_container()->get('config.storage'), drupal_container()->get('dispatcher')); + // Notify event listeners that a configuration context has been created. + $this->notify('context', NULL); + } + +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/Config/ContextInterface.php b/core/lib/Drupal/Core/Config/ContextInterface.php new file mode 100644 index 0000000..f89f5b9 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ContextInterface.php @@ -0,0 +1,43 @@ +addTag('event_subscriber'); $container->register('request_close_subscriber', 'Drupal\Core\EventSubscriber\RequestCloseSubscriber') ->addTag('event_subscriber'); - $container->register('config_global_override_subscriber', 'Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber') + $container->register('config_global_override_subscriber', 'Drupal\Core\EventSubscriber\ConfigOverrideSubscriber') ->addTag('event_subscriber'); $container->register('exception_listener', 'Drupal\Core\EventSubscriber\ExceptionListener') ->addTag('event_subscriber') diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php deleted file mode 100644 index 75c508b..0000000 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php +++ /dev/null @@ -1,42 +0,0 @@ -getFactory()->getContext('config.admin')) { - $config = $event->getConfig(); - if (isset($conf[$config->getName()])) { - $config->setOverride($conf[$config->getName()]); - } - } - } - - /** - * Implements EventSubscriberInterface::getSubscribedEvents(). - */ - static function getSubscribedEvents() { - $events['config.init'][] = array('configInit', 30); - return $events; - } -} diff --git a/core/lib/Drupal/Core/EventSubscriber/ConfigOverrideSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ConfigOverrideSubscriber.php new file mode 100644 index 0000000..a021638 --- /dev/null +++ b/core/lib/Drupal/Core/EventSubscriber/ConfigOverrideSubscriber.php @@ -0,0 +1,42 @@ +getContext()->get(ConfigContext::OVERRIDE)) { + $config = $event->getConfig(); + if (isset($override[$config->getName()])) { + $config->setOverride($override[$config->getName()]); + } + } + } + + /** + * Implements EventSubscriberInterface::getSubscribedEvents(). + */ + static function getSubscribedEvents() { + $events['config.init'][] = array('configInit', 30); + return $events; + } +} diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 2c0924e..44df486 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -18,6 +18,23 @@ * $config is always a DrupalConfig object. */ class LocaleConfigSubscriber implements EventSubscriberInterface { + + /** + * Initialize configuration context with language. + * + * @param Drupal\Core\Config\ConfigEvent $event + * The Event to process. + */ + public function configContext(ConfigEvent $event) { + $context = $event->getContext(); + if (!$context->get('locale.language')) { + // Add user's language for user context. + if ($account = $context->get('user.account')) { + $context->set('locale.language', language_load(user_preferred_langcode($account))); + } + } + } + /** * Override configuration values with localized data. * @@ -25,10 +42,11 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { * The Event to process. */ public function configLoad(ConfigEvent $event) { - if ($language = $event->getFactory()->getContext('locale.language')) { + $context = $event->getContext(); + if ($language = $context->get('locale.language')) { $config = $event->getConfig(); $locale_name = $this->getLocaleConfigName($config->getName(), $language); - if ($override = $config->getStorage()->read($locale_name)) { + if ($override = $context->getStorage()->read($locale_name)) { $config->setOverride($override); } } @@ -48,6 +66,7 @@ public function getLocaleConfigName($name, $language) { * Implements EventSubscriberInterface::getSubscribedEvents(). */ static function getSubscribedEvents() { + $events['config.context'][] = array('configContext', 20); $events['config.load'][] = array('configLoad', 20); return $events; } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 03c78c4..d1422e1 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -1059,20 +1059,8 @@ function _locale_rebuild_js($langcode = NULL) { * Implements hook_language_init(). */ function locale_language_init() { - // Add current language to default configuration factory. - drupal_container()->get('config.factory')->setContext('locale.language', language(LANGUAGE_TYPE_INTERFACE)); + // Add current language to default configuration context. + drupal_container()->get('config.context')->set('locale.language', language(LANGUAGE_TYPE_INTERFACE)); // Add locale helper to configuration subscribers. drupal_container()->get('dispatcher')->addSubscriber(new LocaleConfigSubscriber()); } - -/** - * Implements hook_config_factory(). - */ -function locale_config_factory(ConfigFactory $factory) { - if (!$factory->getContext('locale.language')) { - // Add user's language for user context. - if ($account = $factory->getContext('user.account')) { - $factory->setContext('locale.language', language_load(user_preferred_langcode($account))); - } - } -} diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 890c167..edb3bac 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1377,7 +1377,7 @@ function system_modules_uninstall_submit($form, &$form_state) { * @see system_settings_form() */ function system_site_information_settings($form, &$form_state) { - $site_config = config_admin('system.site'); + $site_config = system_config('system.site'); $site_mail = $site_config->get('mail'); if (empty($site_mail)) { $site_mail = ini_get('sendmail_from'); @@ -1482,7 +1482,7 @@ function system_site_information_settings_validate($form, &$form_state) { * Form submission handler for system_site_information_settings(). */ function system_site_information_settings_submit($form, &$form_state) { - config_admin('system.site') + system_config('system.site') ->set('name', $form_state['values']['site_name']) ->set('mail', $form_state['values']['site_mail']) ->set('slogan', $form_state['values']['site_slogan']) @@ -1522,7 +1522,7 @@ function system_cron_settings($form, &$form_state) { $form['cron']['cron_safe_threshold'] = array( '#type' => 'select', '#title' => t('Run cron every'), - '#default_value' => config_admin('system.cron')->get('threshold.autorun'), + '#default_value' => system_config('system.cron')->get('threshold.autorun'), '#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'), ); @@ -1535,7 +1535,7 @@ function system_cron_settings($form, &$form_state) { * @ingroup forms */ function system_cron_settings_submit($form, &$form_state) { - config_admin('system.cron') + system_config('system.cron') ->set('threshold.autorun', $form_state['values']['cron_safe_threshold']) ->save(); } @@ -1567,7 +1567,7 @@ function system_logging_settings($form, &$form_state) { $form['error_level'] = array( '#type' => 'radios', '#title' => t('Error messages to display'), - '#default_value' => config_admin('system.logging')->get('error_level'), + '#default_value' => system_config('system.logging')->get('error_level'), '#options' => array( ERROR_REPORTING_HIDE => t('None'), ERROR_REPORTING_DISPLAY_SOME => t('Errors and warnings'), @@ -1586,7 +1586,7 @@ function system_logging_settings($form, &$form_state) { * @ingroup forms */ function system_logging_settings_submit($form, &$form_state) { - config_admin('system.logging') + system_config('system.logging') ->set('error_level', $form_state['values']['error_level']) ->save(); } @@ -1599,7 +1599,7 @@ function system_logging_settings_submit($form, &$form_state) { */ function system_performance_settings($form, &$form_state) { drupal_add_library('system', 'drupal.system'); - $config = config_admin('system.performance'); + $config = system_config('system.performance'); $form['clear_cache'] = array( '#type' => 'fieldset', @@ -1688,7 +1688,7 @@ function system_performance_settings($form, &$form_state) { * @ingroup forms */ function system_performance_settings_submit($form, &$form_state) { - $config = config_admin('system.performance'); + $config = system_config('system.performance'); $config->set('cache.page.enabled', $form_state['values']['cache']); $config->set('cache.page.max_age', $form_state['values']['page_cache_maximum_age']); $config->set('response.gzip', $form_state['values']['page_compression']); @@ -1813,7 +1813,7 @@ function system_image_toolkit_settings() { * @ingroup forms */ function system_rss_feeds_settings($form, &$form_state) { - $rss_config = config_admin('system.rss'); + $rss_config = system_config('system.rss'); $form['feed_description'] = array( '#type' => 'textarea', '#title' => t('Feed description'), @@ -1848,7 +1848,7 @@ function system_rss_feeds_settings($form, &$form_state) { * @ingroup forms */ function system_rss_feeds_settings_submit($form, &$form_state) { - config_admin('system.rss') + system_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']) @@ -2149,7 +2149,7 @@ function system_add_date_format_type_form_submit($form, &$form_state) { * @see system_site_maintenance_mode_submit() */ function system_site_maintenance_mode($form, &$form_state) { - $config = config_admin('system.maintenance'); + $config = system_config('system.maintenance'); $form['maintenance_mode'] = array( '#type' => 'checkbox', '#title' => t('Put site into maintenance mode'), @@ -2171,7 +2171,7 @@ function system_site_maintenance_mode($form, &$form_state) { * @ingroup forms */ function system_site_maintenance_mode_submit($form, &$form_state) { - config_admin('system.maintenance') + system_config('system.maintenance') ->set('enabled', $form_state['values']['maintenance_mode']) ->set('message', $form_state['values']['maintenance_mode_message']) ->save(); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 6401361..3b364b5 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -7,6 +7,7 @@ use Drupal\Core\Utility\ModuleInfo; use Drupal\Core\TypedData\Primitive; +use Drupal\Core\Config\Context\AdminContext; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -3412,6 +3413,37 @@ function system_admin_compact_page($mode = 'off') { } /** + * Retrieves a configuration object for administration. + * + * This configuration object will be created using a special configuration + * context (config.admin = TRUE) and configuration plug-ins should mostly keep + * hands off it and don't override it. + * + * This is intended for administration forms or any other case when we need to + * get / set the configuration data without any overrides, as oppossed to + * regular configuration used for runtime operations that may be altered by + * plug-ins depending on other page request parameters: + * + * To get regular configuration objects for the page request use config() + * instead of this function. + * + * @param $name + * The name of the configuration object to retrieve. + * + * @return Drupal\Core\Config\Config + * A configuration object. + * + * @see config() + */ +function system_config($name) { + static $context; + if (!isset($context)) { + $context = new AdminContext('system.config', drupal_container()->get('config.storage')); + } + return config($name, $context); +} + +/** * Generate a list of tasks offered by a specified module. * * @param $module diff --git a/core/modules/user/lib/Drupal/user/UserConfigContext.php b/core/modules/user/lib/Drupal/user/UserConfigContext.php new file mode 100644 index 0000000..7a83757 --- /dev/null +++ b/core/modules/user/lib/Drupal/user/UserConfigContext.php @@ -0,0 +1,27 @@ + array( + 'title' => t('User account'), + 'class' => '\Drupal\user\UserConfigContext', + ), + ); +} + +/** * Implements hook_template_preprocess_default_variables_alter(). * * @see user_user_login() @@ -2074,9 +2087,11 @@ function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) { function user_mail($key, &$message, $params) { $langcode = $message['langcode']; $variables = array('user' => $params['account']); - // Get a configuration object customized for this user, that may be localized - // for the user's language. - $mail_config = config_factory(array('user.account' => $params['account']))->get('user.mail')->load(); + + // Get configuration objects customized for this user, that may be localized + // for the user's language if the locale module is enabled. + $mail_config = config('user.mail', new UserConfigContext($params['account'])); + // We do not sanitize the token replacement, since the output of this // replacement is intended for an e-mail message, not a web browser. $token_options = array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE);