diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 43d1eac..797e505 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2223,6 +2223,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 { @@ -2460,12 +2461,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 3e22534..d7776e0 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -1,6 +1,7 @@ get('config.factory')->get($name)->load(); +function config($name, $context = NULL) { + return drupal_container()->get('config.factory')->get($name, $context)->load(); } /** @@ -179,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(); } } } @@ -245,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 @@ -257,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 24ceaf2..1ef76b6 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 6fc2a87..7021b22 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; -use Symfony\Component\EventDispatcher\EventDispatcher; /** * Defines the default configuration object. @@ -51,34 +50,32 @@ class Config { protected $overriddenData; /** - * The storage used to load and save this configuration object. + * The configuration context used for this configuration object. * - * @var Drupal\Core\Config\StorageInterface + * @var Drupal\Core\Config\ContextInterface */ - protected $storage; + protected $context; /** - * The event dispatcher used to notify subscribers. + * The storage used to load and save this configuration object. * - * @var Symfony\Component\EventDispatcher\EventDispatcher + * @var Drupal\Core\Config\StorageInterface */ - protected $eventDispatcher; + protected $storage; /** * Constructs a configuration object. * * @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 Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher - * The event dispatcher used to notify subscribers. */ - public function __construct($name, StorageInterface $storage, EventDispatcher $event_dispatcher = NULL) { + public function __construct($name, ContextInterface $context) { $this->name = $name; - $this->storage = $storage; - $this->eventDispatcher = $event_dispatcher ? $event_dispatcher : drupal_container()->get('dispatcher'); + $this->context = $context; + $this->storage = $context->getStorage(); } /** @@ -385,21 +382,15 @@ 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; - } /** - * Dispatch a config event. + * Dispatches a config event. + * + * @param $config_event_name + * Event name. */ protected function notify($config_event_name) { - $this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($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 aabd1d8..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,10 +14,23 @@ class ConfigEvent extends Event { protected $config; /** - * Constructor. + * 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 + * (optional) Configuration object. */ - public function __construct(Config $config) { + public function __construct(ContextInterface $context, Config $config = NULL) { $this->config = $config; + $this->context = $context; } /** @@ -26,4 +39,14 @@ public function __construct(Config $config) { public function getConfig() { return $this->config; } + + /** + * Get configuration context object. + * + * @return Drupal\Core\Config\ContextInterface + * Configuration context. + */ + 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 ca36ce7..dec7b4e 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -25,44 +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; - - /** - * 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; + 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 @@ -82,8 +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->eventDispatcher); + $config = new Config($name, $context ?: $this->context); return $config->init(); } + /** + * Gets the default context for this factory. + * + * @return Drupal\Core\Config\ContextInterface + * A configuration context instance. + */ + public function getContext() { + return $this->context; + } + + /** + * Sets the default context for this factory. + * + * @param Drupal\Core\Config\ContextInterface $context + * Context to use to get the configuration. + */ + public function setContext($context) { + $this->context = $context; + } + } 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..8c284a9 --- /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); + } + +} 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..d3c7399 --- /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); + } + +} diff --git a/core/lib/Drupal/Core/Config/ContextInterface.php b/core/lib/Drupal/Core/Config/ContextInterface.php new file mode 100644 index 0000000..e4ce751 --- /dev/null +++ b/core/lib/Drupal/Core/Config/ContextInterface.php @@ -0,0 +1,43 @@ +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 @@ -196,7 +198,7 @@ public function build(ContainerBuilder $container) { ->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 6ee6a3d..0000000 --- a/core/lib/Drupal/Core/EventSubscriber/ConfigGlobalOverrideSubscriber.php +++ /dev/null @@ -1,39 +0,0 @@ -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/config/config.api.php b/core/modules/config/config.api.php index d845667..28cb90f 100644 --- a/core/modules/config/config.api.php +++ b/core/modules/config/config.api.php @@ -124,3 +124,25 @@ function hook_config_import_delete($name, $new_config, $old_config) { return TRUE; } +/** + * Deletes configuration upon synchronizing configuration changes. + * + * This callback is invoked when a new configuration factory is created and + * allows a module to take over the synchronization of configuration data. + * + * Modules should implement this callback if they manage configuration data + * (such as image styles, node types, or fields) which needs to be prepared and + * passed through module API functions to properly handle a configuration + * change. + * + * @param Drupal\Core\Config\ConfigFactory $factory + * A configuration object containing the new configuration data. + */ +function hook_config_factory($factory) { + if (!$factory->getContext('locale.language')) { + // Add user's language when in user's context. + if ($account = $factory->getContext('user.account')) { + $factory->setContext('locale.language', user_preferred_language($account)); + } + } +} diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 3d2fd4a..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,11 +42,13 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { * The Event to process. */ public function configLoad(ConfigEvent $event) { - $config = $event->getConfig(); - $language = language(LANGUAGE_TYPE_INTERFACE); - $locale_name = $this->getLocaleConfigName($config->getName(), $language); - if ($override = $config->getStorage()->read($locale_name)) { - $config->setOverride($override); + $context = $event->getContext(); + if ($language = $context->get('locale.language')) { + $config = $event->getConfig(); + $locale_name = $this->getLocaleConfigName($config->getName(), $language); + if ($override = $context->getStorage()->read($locale_name)) { + $config->setOverride($override); + } } } @@ -47,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 85ed5d1..d1422e1 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -10,6 +10,7 @@ * object files are supported. */ +use Drupal\Core\Config\ConfigFactory; use Drupal\locale\LocaleLookup; use Drupal\locale\LocaleConfigSubscriber; use Drupal\locale\SourceString; @@ -1058,6 +1059,8 @@ function _locale_rebuild_js($langcode = NULL) { * Implements hook_language_init(). */ function locale_language_init() { + // 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()); } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 8c59d82..5a3e1ed 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('system.site'); + $site_config = system_config('system.site'); $site_mail = $site_config->get('mail'); if (empty($site_mail)) { $site_mail = ini_get('sendmail_from'); @@ -1483,7 +1483,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('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']) @@ -1523,7 +1523,7 @@ function system_cron_settings($form, &$form_state) { $form['cron']['cron_safe_threshold'] = array( '#type' => 'select', '#title' => t('Run cron every'), - '#default_value' => config('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'), ); @@ -1536,7 +1536,7 @@ function system_cron_settings($form, &$form_state) { * @ingroup forms */ function system_cron_settings_submit($form, &$form_state) { - config('system.cron') + system_config('system.cron') ->set('threshold.autorun', $form_state['values']['cron_safe_threshold']) ->save(); } @@ -1568,7 +1568,7 @@ function system_logging_settings($form, &$form_state) { $form['error_level'] = array( '#type' => 'radios', '#title' => t('Error messages to display'), - '#default_value' => config('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'), @@ -1587,7 +1587,7 @@ function system_logging_settings($form, &$form_state) { * @ingroup forms */ function system_logging_settings_submit($form, &$form_state) { - config('system.logging') + system_config('system.logging') ->set('error_level', $form_state['values']['error_level']) ->save(); } @@ -1600,7 +1600,7 @@ function system_logging_settings_submit($form, &$form_state) { */ function system_performance_settings($form, &$form_state) { drupal_add_library('system', 'drupal.system'); - $config = config('system.performance'); + $config = system_config('system.performance'); $form['clear_cache'] = array( '#type' => 'fieldset', @@ -1689,7 +1689,7 @@ function system_performance_settings($form, &$form_state) { * @ingroup forms */ function system_performance_settings_submit($form, &$form_state) { - $config = config('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']); @@ -1814,7 +1814,7 @@ function system_image_toolkit_settings() { * @ingroup forms */ function system_rss_feeds_settings($form, &$form_state) { - $rss_config = config('system.rss'); + $rss_config = system_config('system.rss'); $form['feed_description'] = array( '#type' => 'textarea', '#title' => t('Feed description'), @@ -1849,7 +1849,7 @@ function system_rss_feeds_settings($form, &$form_state) { * @ingroup forms */ function system_rss_feeds_settings_submit($form, &$form_state) { - config('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']) @@ -2150,7 +2150,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('system.maintenance'); + $config = system_config('system.maintenance'); $form['maintenance_mode'] = array( '#type' => 'checkbox', '#title' => t('Put site into maintenance mode'), @@ -2172,7 +2172,7 @@ function system_site_maintenance_mode($form, &$form_state) { * @ingroup forms */ function system_site_maintenance_mode_submit($form, &$form_state) { - config('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 950fee6..9e2d43d 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; @@ -3394,6 +3395,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..0c484ce --- /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() @@ -1989,35 +2002,23 @@ function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) { function user_mail($key, &$message, $params) { $langcode = $message['langcode']; $variables = array('user' => $params['account']); - $message['subject'] .= _user_mail_text($key . '.subject', $langcode, $variables); - $message['body'][] = _user_mail_text($key . '.body', $langcode, $variables); -} -/** - * Returns a mail string for a variable name. - * - * @param string $key - * The config key that provides the mail text. - * @param string $langcode - * (optional) A language code to use to generate the e-mail text. - * @param array $variables - * (optional) An array of token keys and values. - * - * @return - * A string value containing the text for the user.mail config key. - */ -function _user_mail_text($key, $langcode = NULL, $variables = array()) { + // 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. - return token_replace(config('user.mail')->get($key), $variables, array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE)); + $token_options = array('langcode' => $langcode, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE); + $message['subject'] .= token_replace($mail_config->get($key . '.subject'), $variables, $token_options); + $message['body'][] = token_replace($mail_config->get($key . '.body'), $variables, $token_options); } /** * Token callback to add unsafe tokens for user mails. * - * This function is used by the token_replace() call at the end of - * _user_mail_text() to set up some additional tokens that can be - * used in email messages generated by user_mail(). + * This function is used by the token_replace() to set up some additional + * tokens that can be used in email messages generated by user_mail(). * * @param $replacements * An associative array variable containing mappings from token names to