diff --git a/core/core.services.yml b/core/core.services.yml index 24ef51e..45c694a 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -68,25 +68,11 @@ services: arguments: ['@config.cachedstorage.storage', '@cache.config'] tags: - { name: persist } - config.context.factory: - class: Drupal\Core\Config\Context\ConfigContextFactory - arguments: ['@event_dispatcher', '@uuid'] - config.context: - class: Drupal\Core\Config\Context\ContextInterface - tags: - - { name: persist } - factory_method: get - factory_service: config.context.factory - config.context.free: - class: Drupal\Core\Config\Context\ContextInterface - factory_method: get - factory_service: config.context.factory - arguments: [Drupal\Core\Config\Context\FreeConfigContext] config.factory: class: Drupal\Core\Config\ConfigFactory tags: - { name: persist } - arguments: ['@config.storage', '@config.context'] + arguments: ['@config.storage', '@event_dispatcher'] config.storage.staging: class: Drupal\Core\Config\FileStorage factory_class: Drupal\Core\Config\FileStorageFactory diff --git a/core/includes/config.inc b/core/includes/config.inc index fa804ac..322be2c 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -16,6 +16,22 @@ */ /** + * Sets the language on the configuration object factory. + * + * @param Drupal\Core\Language\Language $language + * The language that config objects should have injected in to them. + * + * @return Drupal\Core\Language\Language $language + * The language object that was previously set in the config factory. + */ +function config_factory_set_language(Language $language) { + $current_language = Drupal::service('config.factory')->getLanguage(); + drupal_container()->get('config.factory')->setLanguage($language); + Drupal::service('config.factory')->setLanguage($language); + return $current_language; +} + +/** * Installs the default configuration of a given extension. * * When an extension is installed, it searches all the default configuration @@ -131,54 +147,6 @@ function config($name) { } /** - * Sets the config context on the config factory. - * - * This allows configuration objects to be created using special configuration - * contexts eg. global override free or locale using a user preferred language. - * Calling this function affects all subsequent calls to \Drupal::config() until - * config_context_leave() is called. - * - * @see config_context_leave() - * @see \Drupal\Core\Config\ConfigFactory - * - * @param string $context_name - * The name of the config context service on the container or a fully - * qualified class implementing \Drupal\Core\Config\Context\ContextInterface. - * - * @return \Drupal\Core\Config\Context\ContextInterface - * The configuration context object. - */ -function config_context_enter($context_name) { - if (drupal_container()->has($context_name)) { - $context = drupal_container()->get($context_name); - } - elseif (class_exists($context_name) && in_array('Drupal\Core\Config\Context\ContextInterface', class_implements($context_name))) { - $context = drupal_container() - ->get('config.context.factory') - ->get($context_name); - } - else { - throw new ConfigException(sprintf('Unknown config context service or class: %s', $context_name)); - } - drupal_container() - ->get('config.factory') - ->enterContext($context); - return $context; -} - -/** - * Leaves the current config context returning to the previous context. - * - * @see config_context_enter() - * @see \Drupal\Core\Config\ConfigFactory - */ -function config_context_leave() { - drupal_container() - ->get('config.factory') - ->leaveContext(); -} - -/** * Return a list of all config entity types provided by a module. * * @param string $module diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 4c3c340..1087ebf 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -372,17 +372,10 @@ function install_begin_request(&$install_state) { $container->register('event_dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher'); $container->register('config.storage', 'Drupal\Core\Config\InstallStorage'); - $container->register('config.context.factory', 'Drupal\Core\Config\Context\ConfigContextFactory') - ->addArgument(new Reference('event_dispatcher')) - ->addArgument(new Reference('uuid')); - - $container->register('config.context', 'Drupal\Core\Config\Context\ContextInterface') - ->setFactoryService(new Reference('config.context.factory')) - ->setFactoryMethod('get'); $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') ->addArgument(new Reference('config.storage')) - ->addArgument(new Reference('config.context')); + ->addArgument(new Reference('event_dispatcher')); // Register the 'language_manager' service. $container diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 02afbd1..f7016cc 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -9,7 +9,8 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Config\ConfigNameException; -use Drupal\Core\Config\Context\ContextInterface; +use Drupal\Core\Language\Language; +use Symfony\Component\EventDispatcher\EventDispatcher; /** * Defines the default configuration object. @@ -29,6 +30,20 @@ class Config { const MAX_NAME_LENGTH = 250; /** + * An event dispatcher instance to use for configuration events. + * + * @var \Symfony\Component\EventDispatcher\EventDispatcher + */ + protected $eventDispatcher; + + /** + * The Language object used to override configuration data. + * + * @var Drupal\Core\Language\Language + */ + protected $language; + + /** * The name of the configuration object. * * @var string @@ -50,25 +65,32 @@ class Config { protected $data; /** - * The current runtime data ($data + $overrides from Config Context). + * The current runtime data ($data + $languageOverrides + $overrides). * * @var array */ protected $overriddenData; /** - * The storage used to load and save this configuration object. + * The current module language overrides. * - * @var Drupal\Core\Config\StorageInterface + * @var array */ - protected $storage; + protected $languageOverrides; /** - * The configuration context used for this configuration object. + * The current module overrides. * - * @var \Drupal\Core\Config\Context\ContextInterface + * @var array */ - protected $context; + protected $overrides; + + /** + * The storage used to load and save this configuration object. + * + * @var Drupal\Core\Config\StorageInterface + */ + protected $storage; /** * Whether the config object has already been loaded. @@ -85,13 +107,16 @@ class Config { * @param \Drupal\Core\Config\StorageInterface $storage * A storage controller object to use for reading and writing the * configuration data. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context used for this configuration object. + * @param \Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher + * An event dispatcher instance to use for configuration events. + * @param Drupal\Core\Language\Language $language + * The Language object used to override configuration data. */ - public function __construct($name, StorageInterface $storage, ContextInterface $context) { + public function __construct($name, StorageInterface $storage, EventDispatcher $event_dispatcher, Language $language = NULL) { $this->name = $name; $this->storage = $storage; - $this->context = $context; + $this->eventDispatcher = $event_dispatcher; + $this->language = $language; } /** @@ -103,6 +128,7 @@ public function __construct($name, StorageInterface $storage, ContextInterface $ public function init() { $this->isLoaded = FALSE; $this->overrides = array(); + $this->languageOverrides = array(); $this->notify('init'); return $this; } @@ -119,6 +145,7 @@ public function init() { public function initWithData(array $data) { $this->isLoaded = TRUE; $this->overrides = array(); + $this->languageOverrides = array(); $this->isNew = FALSE; $this->notify('init'); $this->replaceData($data); @@ -287,7 +314,24 @@ protected function replaceData(array $data) { * The configuration object. */ public function setOverride(array $data) { - $this->context->setOverrides($this->getName(), $data); + $this->overrides = $data; + $this->resetOverriddenData(); + return $this; + } + + /** + * Sets overridden data for this configuration object. + * + * The overridden data only applies to this configuration object. + * + * @param array $data + * The overridden values of the configuration data. + * + * @return Drupal\Core\Config\Config + * The configuration object. + */ + public function setLanguageOverride(array $data) { + $this->languageOverrides = $data; $this->resetOverriddenData(); return $this; } @@ -302,9 +346,11 @@ public function setOverride(array $data) { */ protected function setOverriddenData() { $this->overriddenData = $this->data; - $overrides = $this->context->getOverrides($this->getName()); - if (is_array($overrides)) { - $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $overrides), TRUE); + if (isset($this->languageOverrides) && is_array($this->languageOverrides)) { + $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->languageOverrides), TRUE); + } + if (isset($this->overrides) && is_array($this->overrides)) { + $this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->overrides), TRUE); } return $this; } @@ -488,7 +534,7 @@ public function getStorage() { * Dispatch a config event. */ protected function notify($config_event_name) { - $this->context->notify($config_event_name, $this); + $this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($this)); } /** @@ -508,4 +554,30 @@ public function merge(array $data_to_merge) { $this->replaceData(NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE)); return $this; } + + /** + * Returns the language object for this Config object. + * + * @return \Drupal\Core\Language\Language + */ + public function getLanguage() { + return $this->language; + } + + /** + * Get configuration name for this language. + * + * It will be the same name with a prefix depending on language code: + * language.config.LANGCODE.NAME + * + * @return string + * The localized config name. + */ + public function getLanguageConfigName() { + if (!isset($this->language)) { + throw new ConfigException("No language set, cannot return language config name for '{$this->name}'"); + } + return 'locale.config.' . $this->language->id . '.' . $this->getName(); + } } + diff --git a/core/lib/Drupal/Core/Config/ConfigEvent.php b/core/lib/Drupal/Core/Config/ConfigEvent.php index 4d49312..e37886c 100644 --- a/core/lib/Drupal/Core/Config/ConfigEvent.php +++ b/core/lib/Drupal/Core/Config/ConfigEvent.php @@ -2,7 +2,6 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\Context\ContextInterface; use Symfony\Component\EventDispatcher\Event; class ConfigEvent extends Event { @@ -15,23 +14,13 @@ class ConfigEvent extends Event { protected $config; /** - * Configuration context object. - * - * @var \Drupal\Core\Config\Context\ContextInterface - */ - protected $context; - - /** * Constructs a configuration event object. * - * @param \Drupal\Core\Config\Context\ContextInterface - * Configuration context object. * @param \Drupal\Core\Config\Config - * (optional) Configuration object. + * Configuration object. */ - public function __construct(ContextInterface $context, Config $config = NULL) { + public function __construct(Config $config) { $this->config = $config; - $this->context = $context; } /** @@ -40,14 +29,5 @@ public function __construct(ContextInterface $context, Config $config = NULL) { public function getConfig() { return $this->config; } - - /** - * Gets configuration context object. - * - * @return \Drupal\Core\Config\Context\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 fe9f4cb..96c5839 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -7,7 +7,8 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\Context\ContextInterface; +use Drupal\Core\Language\Language; +use Symfony\Component\EventDispatcher\EventDispatcher; /** * Defines the configuration object factory. @@ -21,12 +22,6 @@ * is used for reading and writing the configuration data. * * @see Drupal\Core\Config\StorageInterface - * - * A configuration context is an object containing parameters that will be - * available to the configuration plug-ins for them to customize the - * configuration data in different ways. - * - * @see Drupal\Core\Config\Context\ContextInterface */ class ConfigFactory { @@ -38,11 +33,18 @@ class ConfigFactory { protected $storage; /** - * A stack of configuration contexts the last being the context in use. + * An event dispatcher instance to use for configuration events. * - * @var array + * @var \Symfony\Component\EventDispatcher\EventDispatcher + */ + protected $eventDispatcher; + + /** + * The Language object used to override configuration data. + * + * @var Drupal\Core\Language\Language */ - protected $contextStack = array(); + protected $language; /** * Cached configuration objects. @@ -56,12 +58,15 @@ class ConfigFactory { * * @param \Drupal\Core\Config\StorageInterface * The configuration storage engine. - * @param \Drupal\Core\Config\Context\ContextInterface - * Configuration context object. + * @param \Symfony\Component\EventDispatcher\EventDispatcher $event_dispatcher + * An event dispatcher instance to use for configuration events. + * @param \Drupal\Core\Language\Language + * The language for this configuration. */ - public function __construct(StorageInterface $storage, ContextInterface $context) { + public function __construct(StorageInterface $storage, EventDispatcher $event_dispatcher, Language $language = NULL) { $this->storage = $storage; - $this->enterContext($context); + $this->eventDispatcher = $event_dispatcher; + $this->language = $language; } /** @@ -74,18 +79,29 @@ public function __construct(StorageInterface $storage, ContextInterface $context * A configuration object. */ public function get($name) { - $context = $this->getContext(); - $cache_key = $this->getCacheKey($name, $context); + $cache_key = $this->getCacheKey($name); if (isset($this->cache[$cache_key])) { return $this->cache[$cache_key]; } - $this->cache[$cache_key] = new Config($name, $this->storage, $context); - return $this->cache[$cache_key]->init(); + $this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->language); + $this->cache[$cache_key]->init(); + if ($language_overrides = $this->getLanguageOverrides($name)) { + $this->cache[$cache_key]->setLanguageOverride($language_overrides); + } + return $this->cache[$cache_key]; + } + + public function getLanguageOverrides($name) { + $language_name = $this->getLanguageConfigName($name); + if ($language_name && $this->storage->exists($language_name)) { + return $this->storage->read($language_name); + } + return FALSE; } /** - * Returns a list of configuration objects for a given names and context. + * Returns a list of configuration objects for a given names. * * This will pre-load all requested configuration objects does not create * new configuration objects. @@ -97,11 +113,9 @@ public function get($name) { * List of successfully loaded configuration objects, keyed by name. */ public function loadMultiple(array $names) { - $context = $this->getContext(); - $list = array(); foreach ($names as $key => $name) { - $cache_key = $this->getCacheKey($name, $context); + $cache_key = $this->getCacheKey($name); // @todo: Deleted configuration stays in $this->cache, only return // config entities that are not new. if (isset($this->cache[$cache_key]) && !$this->cache[$cache_key]->isNew()) { @@ -114,8 +128,8 @@ public function loadMultiple(array $names) { if (!empty($names)) { $storage_data = $this->storage->readMultiple($names); foreach ($storage_data as $name => $data) { - $cache_key = $this->getCacheKey($name, $context); - $this->cache[$cache_key] = new Config($name, $this->storage, $context); + $cache_key = $this->getCacheKey($name); + $this->cache[$cache_key] = new Config($name, $this->storage, $this->eventDispatcher, $this->language); $this->cache[$cache_key]->initWithData($data); $list[$name] = $this->cache[$cache_key]; } @@ -163,16 +177,15 @@ public function reset($name = NULL) { * The renamed config object. */ public function rename($old_name, $new_name) { - $context = $this->getContext(); - $old_cache_key = $this->getCacheKey($old_name, $context); - $new_cache_key = $this->getCacheKey($new_name, $context); + $old_cache_key = $this->getCacheKey($old_name); + $new_cache_key = $this->getCacheKey($new_name); if (isset($this->cache[$old_cache_key])) { $config = $this->cache[$old_cache_key]; unset($this->cache[$old_cache_key]); } else { // Create the config object if it's not yet loaded into the static cache. - $config = new Config($old_name, $this->storage, $context); + $config = new Config($old_name, $this->storage, $this->eventDispatcher, $this->language); } $this->cache[$new_cache_key] = $config; @@ -181,59 +194,21 @@ public function rename($old_name, $new_name) { } /** - * Sets the config context by adding it to the context stack. - * - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context to add. - * - * @return \Drupal\Core\Config\ConfigFactory - * The config factory object. - */ - public function enterContext(ContextInterface $context) { - // Initialize the context as it is being entered. - $this->contextStack[] = $context->init(); - return $this; - } - - /** - * Gets the current config context. - * - * @return \Drupal\Core\Config\Context\ContextInterface $context - * The current configuration context. - */ - public function getContext() { - return end($this->contextStack); - } - - /** - * Leaves the current context by removing it from the context stack. - * - * @return \Drupal\Core\Config\ConfigFactory - * The config factory object. - */ - public function leaveContext() { - // Ensure at least one context is left on the stack. We already ensured - // there is at least one context set by taking the initial one in the - // constructor. - if (count($this->contextStack) > 1) { - array_pop($this->contextStack); - } - return $this; - } - - /** - * Gets the cache key for a given config name in a particular context. + * Gets the cache key for a given config name. * * @param string $name * The name of the configuration object. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context. * * @return string * The cache key. */ - public function getCacheKey($name, ContextInterface $context) { - return $name . ':' . $context->getUuid(); + public function getCacheKey($name) { + if (isset($this->language)) { + return $this->language->id . ":$name"; + } + else { + return $name; + } } /** @@ -248,7 +223,7 @@ public function getCacheKey($name, ContextInterface $context) { public function getCacheKeys($name) { $cache_keys = array_keys($this->cache); return array_filter($cache_keys, function($key) use ($name) { - return ( strpos($key, $name) !== false ); + return strpos($key, $name) !== FALSE; }); } @@ -262,4 +237,44 @@ public function clearStaticCache() { $this->cache = array(); return $this; } + + /** + * Set the language to be injected in to Config objects. + * + * @param Language $language + * @return ConfigFactory + */ + public function setLanguage(Language $language) { + $this->language = $language; + return $this; + } + + /** + * Get the language to be injected in to Config objects. + * + * @return Drupal\Core\Language\Language + */ + public function getLanguage() { + return $this->language; + } + + /** + * Get configuration name for this language. + * + * It will be the same name with a prefix depending on language code: + * language.config.LANGCODE.NAME + * + * @param string $name + * The name of the config object. + * + * @return string + * The localized config name. + */ + public function getLanguageConfigName($name) { + if (!isset($this->language)) { + return FALSE; + } + return 'locale.config.' . $this->language->id . '.' . $name; + } } + diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index ba2ece6..0e1c182 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\Context\FreeConfigContext; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Component\Uuid\UuidInterface; @@ -54,13 +53,6 @@ class ConfigImporter { protected $eventDispatcher; /** - * The configuration context. - * - * @var \Drupal\Core\Config\Context\ContextInterface - */ - protected $context; - - /** * The configuration factory. * * @var \Drupal\Core\Config\ConfigFactory @@ -127,10 +119,6 @@ public function __construct(StorageComparerInterface $storage_comparer, EventDis $this->lock = $lock; $this->uuidService = $uuid_service; $this->processed = $this->storageComparer->getEmptyChangelist(); - // Use an override free context for importing so that overrides to do not - // pollute the imported data. The context is hard coded to ensure this is - // the case. - $this->context = new FreeConfigContext($this->eventDispatcher, $this->uuidService); } /** @@ -224,7 +212,6 @@ public function import() { // Ensure that the changes have been validated. $this->validate(); - $this->configFactory->enterContext($this->context); if (!$this->lock->acquire(static::ID)) { // Another process is synchronizing configuration. throw new ConfigImporterException(sprintf('%s is already importing', static::ID)); @@ -237,9 +224,6 @@ public function import() { // The import is now complete. $this->lock->release(static::ID); $this->reset(); - // Leave the context used during import and clear the ConfigFactory's - // static cache. - $this->configFactory->leaveContext()->reset(); } return $this; } @@ -264,7 +248,7 @@ public function validate() { protected function importConfig() { foreach (array('delete', 'create', 'update') as $op) { foreach ($this->getUnprocessed($op) as $name) { - $config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + $config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher); if ($op == 'delete') { $config->delete(); } @@ -297,11 +281,11 @@ protected function importInvokeOwner() { // Validate the configuration object name before importing it. // Config::validateName($name); if ($entity_type = config_get_entity_type_by_name($name)) { - $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + $old_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher); $old_config->load(); $data = $this->storageComparer->getSourceStorage()->read($name); - $new_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->context); + $new_config = new Config($name, $this->storageComparer->getTargetStorage(), $this->eventDispatcher); if ($data !== FALSE) { $new_config->setData($data); } diff --git a/core/lib/Drupal/Core/Config/Context/ConfigContext.php b/core/lib/Drupal/Core/Config/Context/ConfigContext.php deleted file mode 100644 index 128165b..0000000 --- a/core/lib/Drupal/Core/Config/Context/ConfigContext.php +++ /dev/null @@ -1,141 +0,0 @@ -eventDispatcher = $event_dispatcher; - $this->uuidService = $uuid; - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::init(). - */ - public function init() { - // Reset existing overrides and get a UUID for this context. - $this->overrides = array(); - $this->setUuid(); - // Notify event listeners that a configuration context has been created. - $this->notify('context', NULL); - return $this; - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::get(). - */ - public function get($key) { - return array_key_exists($key, $this->data) ? $this->data[$key] : NULL; - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::set(). - */ - public function set($key, $value) { - $this->data[$key] = $value; - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::setUuid(). - */ - public function setUuid() { - $this->uuid = $this->uuidService->generate(); - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::getUuid(). - */ - public function getUuid() { - return $this->uuid; - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::notify(). - */ - public function notify($config_event_name, Config $config = NULL) { - $this->eventDispatcher->dispatch('config.' . $config_event_name, new ConfigEvent($this, $config)); - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::setOverride(). - */ - public function setOverrides($config_name, $data) { - if (!isset($this->overrides[$config_name])) { - $this->overrides[$config_name] = $data; - } - else { - $this->overrides[$config_name] = NestedArray::mergeDeepArray(array($this->overrides[$config_name], $data), TRUE); - } - } - - /** - * Implements \Drupal\Core\Config\Context\ContextInterface::getOverrides(). - */ - public function getOverrides($config_name) { - if (isset($this->overrides[$config_name])) { - return $this->overrides[$config_name]; - } - return FALSE; - } - -} diff --git a/core/lib/Drupal/Core/Config/Context/ConfigContextFactory.php b/core/lib/Drupal/Core/Config/Context/ConfigContextFactory.php deleted file mode 100644 index de3fd7b..0000000 --- a/core/lib/Drupal/Core/Config/Context/ConfigContextFactory.php +++ /dev/null @@ -1,74 +0,0 @@ -eventDispatcher = $event_dispatcher; - $this->uuidService = $uuid; - } - - /** - * Returns a configuration context object. - * - * @param string $class - * (Optional) The name of the configuration class to use. Defaults to - * Drupal\Core\Config\Context\ConfigContext - * - * @return \Drupal\Core\Config\Context\ContextInterface $context - * (Optional) The configuration context to use. - */ - public function get($class = NULL) { - if (!$class) { - $class = 'Drupal\Core\Config\Context\ConfigContext'; - } - if (class_exists($class)) { - $context = new $class($this->eventDispatcher, $this->uuidService); - } - else { - throw new ConfigException(sprintf('Unknown config context class: %s', $class)); - } - return $context; - } - -} diff --git a/core/lib/Drupal/Core/Config/Context/ContextInterface.php b/core/lib/Drupal/Core/Config/Context/ContextInterface.php deleted file mode 100644 index e7e4904..0000000 --- a/core/lib/Drupal/Core/Config/Context/ContextInterface.php +++ /dev/null @@ -1,101 +0,0 @@ -configFactory = $config_factory; - $this->configFactory->enterContext($context); } /** @@ -42,8 +38,7 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con */ public static function create(ContainerInterface $container) { return new static( - $container->get('config.factory'), - $container->get('config.context.free') + $container->get('config.factory') ); } @@ -78,7 +73,6 @@ protected function config($name) { if (!$this->configFactory) { $container = $this->container(); $this->configFactory = $container->get('config.factory'); - $this->configFactory->enterContext($container->get('config.context.free')); } return $this->configFactory->get($name); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php index 85e96e0..c8c6ff7 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php @@ -9,7 +9,6 @@ use Drupal\aggregator\Plugin\AggregatorPluginManager; use Drupal\Component\Utility\String; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\StringTranslation\TranslationInterface; @@ -51,8 +50,6 @@ class SettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context to use. * @param \Drupal\aggregator\Plugin\AggregatorPluginManager $fetcher_manager * The aggregator fetcher plugin manager. * @param \Drupal\aggregator\Plugin\AggregatorPluginManager $parser_manager @@ -62,8 +59,8 @@ class SettingsForm extends ConfigFormBase { * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager * The string translation manager. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $translation_manager) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $translation_manager) { + parent::__construct($config_factory); $this->translationManager = $translation_manager; $this->managers = array( 'fetcher' => $fetcher_manager, @@ -84,7 +81,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('plugin.manager.aggregator.fetcher'), $container->get('plugin.manager.aggregator.parser'), $container->get('plugin.manager.aggregator.processor'), diff --git a/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php b/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php index 9c120c3..139a5ba 100644 --- a/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php +++ b/core/modules/aggregator/tests/Drupal/aggregator/Tests/Plugin/AggregatorPluginSettingsBaseTest.php @@ -67,7 +67,6 @@ public function setUp() { $this->settingsForm = new SettingsForm( $this->configFactory, - $this->getMock('Drupal\Core\Config\Context\ContextInterface'), $this->managers['fetcher'], $this->managers['parser'], $this->managers['processor'], diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php index da65a09..e921876 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php @@ -16,6 +16,7 @@ use Drupal\Core\Config\ConfigImporter; use Drupal\Core\Config\ConfigException; use Drupal\Core\Config\ConfigFactory; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php index 99fbaea..f5ff1b5 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImporterTest.php @@ -61,7 +61,8 @@ function setUp() { $this->container->get('config.factory'), $this->container->get('entity.manager'), $this->container->get('lock'), - $this->container->get('uuid') + $this->container->get('uuid'), + $this->container->get('module_handler') ); $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.staging')); } @@ -209,6 +210,7 @@ function testUpdated() { $this->configImporter->reset()->import(); // Verify the values were updated. + \Drupal::service('config.factory')->reset($name); $config = \Drupal::config($name); $this->assertIdentical($config->get('foo'), 'beer'); $config = \Drupal::config($dynamic_name); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php index f3f3ea6..e047806 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverride.php @@ -35,6 +35,7 @@ public function setUp() { parent::setUp(); config_install_default_config('module', 'config_test'); config_install_default_config('module', 'locale'); + \Drupal::service('config.factory')->setLanguage(language_default()); } /** @@ -42,256 +43,30 @@ public function setUp() { */ function testConfigLocaleOverride() { $name = 'config_test.system'; - // The default language is en so the config key should be localised. $config = \Drupal::config($name); $this->assertIdentical($config->get('foo'), 'en bar'); - $this->assertIdentical($config->get('404'), 'herp'); - - // Ensure that we get the expected value when we avoid overrides. - config_context_enter('config.context.free'); - $config_admin = \Drupal::config($name); - $this->assertIdentical($config_admin->get('foo'), 'bar'); - $this->assertIdentical($config_admin->get('404'), 'herp'); - - // Leave the non override context. - config_context_leave(); - $config = \Drupal::config($name); - $this->assertIdentical($config->get('foo'), 'en bar'); - $this->assertIdentical($config->get('404'), 'herp'); - } - - /** - * Tests locale override based on user's preferred language. - */ - function testConfigLocaleUserOverride() { - $this->installSchema('system', 'variable'); - $this->installConfig(array('language')); - language_save(new Language(array( - 'name' => 'French', - 'id' => 'fr', - ))); - language_save(new Language(array( - 'name' => 'English', - 'id' => 'en', - ))); - language_save(new Language(array( - 'name' => 'German', - 'id' => 'de', - ))); - - $this->installSchema('user', 'users'); - $account = entity_create('user', array( - 'name' => 'French user', - 'mail' => 'test@example.com', - 'created' => REQUEST_TIME, - 'status' => 1, - 'preferred_langcode' => 'fr', - )); - - $user_config_context = config_context_enter('Drupal\user\UserConfigContext'); - $user_config_context->setAccount($account); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'fr bar'); - // Ensure the non-overriden value is still the same. - $this->assertIdentical($config->get('404'), 'herp'); - - // Ensure that we get the expected value when we leave the user context. The - // locale overrides contain an English override too, so although we are not - // in a user based language override context, the English language override - // applies due to the negotiated language for the page. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - - $account = entity_create('user', array( - 'name' => 'German user', - 'mail' => 'test@example.com', - 'created' => REQUEST_TIME, - 'status' => 1, - 'preferred_langcode' => 'de', - )); - - $config_factory = \Drupal::service('config.factory'); - $config_factory->enterContext($user_config_context->setAccount($account)); - // Should not have to re-initialize the configuration object to get new - // overrides as the new context will have a different uuid. - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'de bar'); - - // Enter an english context on top of the german context. - $account = entity_create('user', array( - 'name' => 'English user', - 'mail' => 'test@example.com', - 'created' => REQUEST_TIME, - 'status' => 1, - 'preferred_langcode' => 'en', - )); - // Create a new user config context to stack on top of the existign one. - $en_user_config_context = config_context_enter('Drupal\user\UserConfigContext'); - $en_user_config_context->setAccount($account); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - - // Ensure that we get the expected value when we leave the english user - // context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'de bar'); - - // Ensure that we get the expected value when we leave the german user - // context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - - // Ensure that we cannot leave the default context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); } /** * Tests locale override based on language. */ function testConfigLocaleLanguageOverride() { - $this->installSchema('system', 'variable'); - $this->installConfig(array('language')); language_save(new Language(array( 'name' => 'French', 'id' => 'fr', ))); language_save(new Language(array( - 'name' => 'English', - 'id' => 'en', - ))); - language_save(new Language(array( 'name' => 'German', 'id' => 'de', ))); - $language = language_load('fr'); - $language_config_context = config_context_enter('Drupal\language\LanguageConfigContext'); - $language_config_context->setLanguage($language); + \Drupal::service('config.factory')->setLanguage(language_load('fr')); $config = \Drupal::config('config_test.system'); $this->assertIdentical($config->get('foo'), 'fr bar'); - // Ensure the non-overridden value is still the same. - $this->assertIdentical($config->get('404'), 'herp'); - - // Ensure that we get the expected value when we leave the language context. The - // locale overrides contain an English override too, so although we are not - // in a language override context, the English language override - // applies due to the negotiated language for the page. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - $config_factory = \Drupal::service('config.factory'); - $language = language_load('de'); - $config_factory->enterContext($language_config_context->setLanguage($language)); - // Should not have to re-initialize the configuration object to get new - // overrides as the new context will have a different uuid. + \Drupal::service('config.factory')->setLanguage(language_load('de')); $config = \Drupal::config('config_test.system'); $this->assertIdentical($config->get('foo'), 'de bar'); - - // Enter an english context on top of the german context. - $language = language_load('en'); - // Create a new language config context to stack on top of the existing one. - $en_language_config_context = config_context_enter('Drupal\language\LanguageConfigContext'); - $en_language_config_context->setLanguage($language); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - - // Ensure that we get the expected value when we leave the english - // language context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'de bar'); - - // Ensure that we get the expected value when we leave the german - // language context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - - // Ensure that we cannot leave the default context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - } - - /** - * Tests locale override in combination with global overrides. - */ - function testConfigLocaleUserAndGlobalOverride() { - global $conf; - - // Globally override value for the keys in config_test.system. Although we - // override the foo key, there are also language overrides, which trump - // global overrides so the 'foo' key override will never surface. - $conf['config_test.system']['foo'] = 'global bar'; - $conf['config_test.system']['404'] = 'global herp'; - - $this->installSchema('system', 'variable'); - $this->installConfig(array('language')); - language_save(new Language(array( - 'name' => 'French', - 'id' => 'fr', - ))); - - $this->installSchema('user', 'users'); - $account = entity_create('user', array( - 'name' => 'French user', - 'mail' => 'test@example.com', - 'created' => REQUEST_TIME, - 'status' => 1, - 'preferred_langcode' => 'fr', - )); - - $user_config_context = config_context_enter('Drupal\user\UserConfigContext'); - $user_config_context->setAccount($account); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'fr bar'); - // Ensure the value overriden from global $conf works. - $this->assertIdentical($config->get('404'), 'global herp'); - - // Ensure that we get the expected value when we leave the user context. The - // locale overrides contain an English override too, so although we are not - // in a user based language override context, the English language override - // applies due to the negotiated language for the page. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - // Global override should still apply. - $this->assertIdentical($config->get('404'), 'global herp'); - - // Ensure that we cannot leave the default context. - config_context_leave(); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), 'en bar'); - // Global override should still apply. - $this->assertIdentical($config->get('404'), 'global herp'); - - // Ensure that we get the expected value when we avoid overrides. - config_context_enter('config.context.free'); - $config_admin = \Drupal::config('config_test.system'); - // Language override should not apply anymore. - $this->assertIdentical($config_admin->get('foo'), 'bar'); - // Global override should not apply. - $this->assertIdentical($config_admin->get('404'), 'herp'); - config_context_leave(); - } - - /** - * Tests config_context_enter() invalid context name handling. - */ - function testInvalidContextName() { - $message = 'Expected ConfigException was thrown for an invalid context_name argument.'; - try { - config_context_enter('invalid.config.context'); - $this->fail($message); - } - catch (ConfigException $e) { - $this->pass($message); - } } } + diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php index f98a1e0..b5014c4 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php @@ -54,16 +54,6 @@ function testSiteNameTranslation() { // The home page in English should not have the override. $this->drupalGet(''); $this->assertNoText('XX site name'); - - // During path resolution the system.site configuration object is used to - // determine the front page. This occurs before language negotiation causing - // the configuration factory to cache an object without the correct - // overrides. We are testing that the configuration factory is - // re-initialised after language negotiation. Ensure that it applies when - // we access the XX front page. - // @see \Drupal\Core\PathProcessor::processInbound() - $this->drupalGet('xx'); - $this->assertText('XX site name'); } - } + diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php index a6016c3..25b0ff1 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php @@ -61,14 +61,6 @@ function testConfOverride() { $this->assertFalse(isset($data['baz'])); $this->assertIdentical($data['404'], $expected_original_data['404']); - // Enter an override-free context to ensure the original data remains. - config_context_enter('config.context.free'); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), $expected_original_data['foo']); - $this->assertIdentical($config->get('baz'), $expected_original_data['baz']); - $this->assertIdentical($config->get('404'), $expected_original_data['404']); - config_context_leave(); - // Get the configuration object in an overriden context (the one set by // default). $config = \Drupal::config('config_test.system'); @@ -100,14 +92,6 @@ function testConfOverride() { $this->assertIdentical($config->get('baz'), $conf['config_test.system']['baz']); $this->assertIdentical($config->get('404'), $conf['config_test.system']['404']); - // Enter an override-free context to ensure the original data remains saved. - config_context_enter('config.context.free'); - $config = \Drupal::config('config_test.system'); - $this->assertIdentical($config->get('foo'), $expected_original_data['foo']); - $this->assertIdentical($config->get('baz'), $expected_original_data['baz']); - $this->assertIdentical($config->get('404'), $expected_original_data['404']); - config_context_leave(); - // Write file to staging. $staging = $this->container->get('config.storage.staging'); $expected_new_data = array( diff --git a/core/modules/language/lib/Drupal/language/Form/ContentLanguageSettingsForm.php b/core/modules/language/lib/Drupal/language/Form/ContentLanguageSettingsForm.php index f4d7c54..9812892 100644 --- a/core/modules/language/lib/Drupal/language/Form/ContentLanguageSettingsForm.php +++ b/core/modules/language/lib/Drupal/language/Form/ContentLanguageSettingsForm.php @@ -8,7 +8,6 @@ namespace Drupal\language\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,13 +29,11 @@ class ContentLanguageSettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The config factory. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context to use. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, EntityManager $entity_manager) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, EntityManager $entity_manager) { + parent::__construct($config_factory); $this->entityManager = $entity_manager; } @@ -47,7 +44,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('plugin.manager.entity') ); } diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php index b801b2b..9271be5 100644 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationBrowserForm.php @@ -8,7 +8,6 @@ namespace Drupal\language\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -31,8 +30,8 @@ class NegotiationBrowserForm extends ConfigFormBase { * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, ModuleHandlerInterface $module_handler) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) { + parent::__construct($config_factory); $this->moduleHandler = $module_handler; } @@ -42,7 +41,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('module_handler') ); } @@ -196,5 +194,5 @@ protected function language_get_browser_drupal_langcode_mappings() { } return $config->get(); } - } + diff --git a/core/modules/language/lib/Drupal/language/LanguageConfigContext.php b/core/modules/language/lib/Drupal/language/LanguageConfigContext.php deleted file mode 100644 index 58b83a6..0000000 --- a/core/modules/language/lib/Drupal/language/LanguageConfigContext.php +++ /dev/null @@ -1,44 +0,0 @@ -set(self::LANGUAGE_KEY, $language); - // Re-initialize since the language change changes the context fundamentally. - $this->init(); - return $this; - } - -} diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 11fa899..36ef201 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -7,8 +7,6 @@ namespace Drupal\locale; use Drupal\Core\Config\Config; -use Drupal\Core\Config\Context\ConfigContext; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Config\ConfigEvent; use Drupal\Core\Config\StorageDispatcher; use Drupal\Core\Language\Language; @@ -18,7 +16,6 @@ use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; - /** * Locale Config helper * @@ -34,66 +31,13 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { protected $languageManager; /** - * Default configuration context. - * - * @var \Drupal\Core\Config\Context\ContextInterface - */ - protected $defaultConfigContext; - - /** * Constructs a LocaleConfigSubscriber object. * * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager service. - * @param \Drupal\Core\Config\Context\ConfigContext $config_context - * The configuration context service. */ - public function __construct(LanguageManager $language_manager, ContextInterface $config_context) { + public function __construct(LanguageManager $language_manager) { $this->languageManager = $language_manager; - $this->defaultConfigContext = $config_context; - } - - /** - * Initializes configuration context with language. - * - * @param \Drupal\Core\Config\ConfigEvent $event - * The Event to process. - */ - public function configContext(ConfigEvent $event) { - $context = $event->getContext(); - - // If there is a language set explicitly in the current context, use it. - // Otherwise check if there is a user set in the current context, - // to set the language based on the preferred language of the user. - // Otherwise set it based on the negotiated interface language. - if ($language = $context->get('language')) { - $context->set('locale.language', $language); - } - elseif ($account = $context->get('user.account')) { - $context->set('locale.language', language_load($account->getPreferredLangcode())); - } - elseif ($language = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)) { - $context->set('locale.language', $language); - } - } - - /** - * Override configuration values with localized data. - * - * @param \Drupal\Core\Config\ConfigEvent $event - * The Event to process. - */ - public function configLoad(ConfigEvent $event) { - $context = $event->getContext(); - if ($language = $context->get('locale.language')) { - $config = $event->getConfig(); - $locale_name = $this->getLocaleConfigName($config->getName(), $language); - // Check to see if the config storage has an appropriately named file - // containing override data. - if ($override = $event->getConfig()->getStorage()->read($locale_name)) { - $config->setOverride($override); - } - } } /** @@ -102,12 +46,8 @@ public function configLoad(ConfigEvent $event) { * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event * Kernel event to respond to. */ - public function onKernelRequestSetDefaultConfigContextLocale(GetResponseEvent $event) { - // Re-initialize the default configuration context to ensure any cached - // configuration object are reset and can be translated. This will invoke - // the config context event which will retrieve the negotiated language - // from the language manager in configContext(). - $this->defaultConfigContext->init(); + public function onKernelRequestSetDefaultConfigLanguage(GetResponseEvent $event) { + // Set the language on the ConfigFactory based on whatever we negotiate. } /** @@ -132,11 +72,8 @@ public function getLocaleConfigName($name, Language $language) { * Implements EventSubscriberInterface::getSubscribedEvents(). */ static function getSubscribedEvents() { - $events['config.context'][] = array('configContext', 20); - $events['config.load'][] = array('configLoad', 20); - // Set the priority above the one from the RouteListener (priority 32) - // so ensure that the context is cleared before the routing system steps in. - $events[KernelEvents::REQUEST][] = array('onKernelRequestSetDefaultConfigContextLocale', 48); + $events[KernelEvents::REQUEST][] = array('onKernelRequestSetDefaultConfigLanguage', 48); return $events; } } + diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml index f632704..1d5bff3 100644 --- a/core/modules/locale/locale.services.yml +++ b/core/modules/locale/locale.services.yml @@ -3,7 +3,7 @@ services: class: Drupal\locale\LocaleConfigSubscriber tags: - { name: event_subscriber } - arguments: ['@language_manager', '@config.context'] + arguments: ['@language_manager'] locale.config.typed: class: Drupal\locale\LocaleConfigManager arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage'] diff --git a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php index 3f21186..758ebb8 100644 --- a/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php +++ b/core/modules/search/lib/Drupal/search/Form/SearchSettingsForm.php @@ -7,7 +7,6 @@ namespace Drupal\search\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\Plugin\PluginFormInterface; @@ -53,8 +52,6 @@ class SearchSettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The configuration factory object that manages search settings. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The context interface * @param \Drupal\search\SearchPluginManager $manager * The manager for search plugins. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler @@ -62,8 +59,8 @@ class SearchSettingsForm extends ConfigFormBase { * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state * The state key/value store interface, gives access to state based config settings. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, SearchPluginManager $manager, ModuleHandlerInterface $module_handler, KeyValueStoreInterface $state) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, SearchPluginManager $manager, ModuleHandlerInterface $module_handler, KeyValueStoreInterface $state) { + parent::__construct($config_factory); $this->searchSettings = $config_factory->get('search.settings'); $this->searchPluginManager = $manager; $this->moduleHandler = $module_handler; @@ -76,7 +73,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('plugin.manager.search'), $container->get('module_handler'), $container->get('state') diff --git a/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php index 437946f..0b44e96 100644 --- a/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php +++ b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php @@ -6,7 +6,6 @@ namespace Drupal\statistics; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Config\ConfigFactory; @@ -29,13 +28,11 @@ class StatisticsSettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, ModuleHandlerInterface $module_handler) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) { + parent::__construct($config_factory); $this->moduleHandler = $module_handler; } @@ -46,7 +43,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('module_handler') ); } @@ -95,5 +91,5 @@ public function submitForm(array &$form, array &$form_state) { parent::submitForm($form, $form_state); } - } + diff --git a/core/modules/system/lib/Drupal/system/Form/CronForm.php b/core/modules/system/lib/Drupal/system/Form/CronForm.php index 12802e4..431de71 100644 --- a/core/modules/system/lib/Drupal/system/Form/CronForm.php +++ b/core/modules/system/lib/Drupal/system/Form/CronForm.php @@ -8,7 +8,6 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -31,13 +30,11 @@ class CronForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context used for this configuration object. * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state * The state key value store. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, KeyValueStoreInterface $state) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, KeyValueStoreInterface $state) { + parent::__construct($config_factory); $this->state = $state; } @@ -47,7 +44,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('state') ); } diff --git a/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php index dcdb2cc..572cdd8 100644 --- a/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php @@ -8,7 +8,6 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\system\Plugin\ImageToolkitManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,13 +29,11 @@ class ImageToolkitForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context used for this configuration object. * @param \Drupal\system\Plugin\ImageToolkitManager $manager * The image toolkit plugin manager. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, ImageToolkitManager $manager) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, ImageToolkitManager $manager) { + parent::__construct($config_factory); foreach ($manager->getAvailableToolkits() as $id => $definition) { $this->availableToolkits[$id] = $manager->createInstance($id); @@ -49,7 +46,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('image.toolkit.manager') ); } diff --git a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php index ff4e8fd..6fdd391 100644 --- a/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php +++ b/core/modules/system/lib/Drupal/system/Form/PerformanceForm.php @@ -9,7 +9,6 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Cache\CacheBackendInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,12 +29,10 @@ class PerformanceForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context used for this configuration object. * @param \Drupal\Core\Cache\CacheBackendInterface $page_cache */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, CacheBackendInterface $page_cache) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, CacheBackendInterface $page_cache) { + parent::__construct($config_factory); $this->pageCache = $page_cache; } @@ -46,7 +43,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('cache.page') ); } diff --git a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php index 569a5c6..0809910 100644 --- a/core/modules/system/lib/Drupal/system/Form/RegionalForm.php +++ b/core/modules/system/lib/Drupal/system/Form/RegionalForm.php @@ -8,7 +8,6 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Locale\CountryManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,13 +29,11 @@ class RegionalForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context used for this configuration object. * @param \Drupal\Core\Locale\CountryManagerInterface $country_manager * The country manager. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, CountryManagerInterface $country_manager) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, CountryManagerInterface $country_manager) { + parent::__construct($config_factory); $this->countryManager = $country_manager; } @@ -46,7 +43,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('country_manager') ); } diff --git a/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php index 1b5029b..0585c1a 100644 --- a/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php +++ b/core/modules/system/lib/Drupal/system/Form/SiteInformationForm.php @@ -8,7 +8,6 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Path\AliasManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,13 +29,11 @@ class SiteInformationForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context used for this configuration object. * @param \Drupal\Core\Path\AliasManagerInterface $alias_manager * The path alias manager. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, AliasManagerInterface $alias_manager) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, AliasManagerInterface $alias_manager) { + parent::__construct($config_factory); $this->aliasManager = $alias_manager; } @@ -47,7 +44,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('path.alias_manager') ); } diff --git a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php index 131af5b..90ac23e 100644 --- a/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php +++ b/core/modules/system/lib/Drupal/system/Form/SiteMaintenanceModeForm.php @@ -8,7 +8,6 @@ namespace Drupal\system\Form; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\Form\ConfigFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,13 +29,11 @@ class SiteMaintenanceModeForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context to use. * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state * The state keyvalue collection to use. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, KeyValueStoreInterface $state) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, KeyValueStoreInterface $state) { + parent::__construct($config_factory); $this->state = $state; } @@ -46,7 +43,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('state') ); } diff --git a/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php b/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php index 44b34fe..055efce 100644 --- a/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ThemeSettingsForm.php @@ -12,7 +12,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; @@ -33,13 +32,11 @@ class ThemeSettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface * The module handler instance to use. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, ModuleHandlerInterface $module_handler) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, ModuleHandlerInterface $module_handler) { + parent::__construct($config_factory); $this->moduleHandler = $module_handler; } @@ -50,7 +47,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('module_handler') ); } diff --git a/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php b/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php index f9965f9..237473a 100644 --- a/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php +++ b/core/modules/system/lib/Drupal/system/SystemConfigSubscriber.php @@ -9,8 +9,6 @@ use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigImporterEvent; use Drupal\Core\Config\ConfigImporterException; -use Drupal\Core\Config\Context\ConfigContext; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Config\ConfigEvent; use Drupal\Core\Config\StorageDispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/core/modules/user/lib/Drupal/user/AccountSettingsForm.php b/core/modules/user/lib/Drupal/user/AccountSettingsForm.php index e8077d3..96c2b55 100644 --- a/core/modules/user/lib/Drupal/user/AccountSettingsForm.php +++ b/core/modules/user/lib/Drupal/user/AccountSettingsForm.php @@ -9,7 +9,6 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Config\ConfigFactory; -use Drupal\Core\Config\Context\ContextInterface; use Drupal\Core\Extension\ModuleHandler; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,13 +29,11 @@ class AccountSettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactory $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Config\Context\ContextInterface $context - * The configuration context. * @param \Drupal\Core\Extension\ModuleHandler $module_handler * The module handler. */ - public function __construct(ConfigFactory $config_factory, ContextInterface $context, ModuleHandler $module_handler) { - parent::__construct($config_factory, $context); + public function __construct(ConfigFactory $config_factory, ModuleHandler $module_handler) { + parent::__construct($config_factory); $this->moduleHandler = $module_handler; } @@ -46,7 +43,6 @@ public function __construct(ConfigFactory $config_factory, ContextInterface $con public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('config.context.free'), $container->get('module_handler') ); } diff --git a/core/modules/user/lib/Drupal/user/UserConfigContext.php b/core/modules/user/lib/Drupal/user/UserConfigContext.php deleted file mode 100644 index 1d5f497..0000000 --- a/core/modules/user/lib/Drupal/user/UserConfigContext.php +++ /dev/null @@ -1,45 +0,0 @@ -set(self::USER_KEY, $account); - // Re-initialize since the user change changes the context fundamentally. - $this->init(); - return $this; - } - -} diff --git a/core/modules/user/user.module b/core/modules/user/user.module index c73155b..54d9f06 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1410,12 +1410,10 @@ function user_mail($key, &$message, $params) { $langcode = $message['langcode']; $variables = array('user' => $params['account']); - // Get configuration objects customized for the user specified in $params as - // this user is not necessarily the same as the one triggering the mail. This - // allows the configuration objects to be localized for the user's language if - // the locale module is enabled. - $user_config_context = config_context_enter('Drupal\user\UserConfigContext'); - $user_config_context->setAccount($params['account']); + $original_language = \Drupal::configFactory()->getLanguage(); + + $language = language_load($params['account']->getPreferredLangcode()); + \Drupal::configFactory()->setLanguage($language); $mail_config = \Drupal::config('user.mail'); // We do not sanitize the token replacement, since the output of this @@ -1424,8 +1422,7 @@ function user_mail($key, &$message, $params) { $message['subject'] .= $token_service->replace($mail_config->get($key . '.subject'), $variables, $token_options); $message['body'][] = $token_service->replace($mail_config->get($key . '.body'), $variables, $token_options); - // Return the previous config context. - config_context_leave(); + \Drupal::configFactory()->setLanguage($original_language); } /** diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 75d051d..fba504a 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -10,7 +10,6 @@ use Drupal\Component\Utility\Settings; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\NullStorage; -use Drupal\Core\Config\Context\ConfigContextFactory; use Drupal\Core\PathProcessor\PathProcessorAlias; use Drupal\Core\PathProcessor\PathProcessorManager; use Symfony\Component\EventDispatcher\EventDispatcher;