diff --git a/core/lib/Drupal/Core/Config/Context/GlobalConfigContext.php b/core/lib/Drupal/Core/Config/Context/GlobalConfigContext.php new file mode 100644 index 0000000..777cb23 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Context/GlobalConfigContext.php @@ -0,0 +1,29 @@ +init(self::OVERRIDE, $conf); + return $this; + } +} diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php index 336b1f1..bb2e39c 100644 --- a/core/lib/Drupal/Core/CoreBundle.php +++ b/core/lib/Drupal/Core/CoreBundle.php @@ -34,7 +34,6 @@ class CoreBundle extends Bundle { * Implements \Symfony\Component\HttpKernel\Bundle\BundleInterface::build(). */ public function build(ContainerBuilder $container) { - global $conf; // Register active configuration storage. $container @@ -58,7 +57,8 @@ public function build(ContainerBuilder $container) { $container->register('config.context', 'Drupal\Core\Config\Context\ContextInterface') ->setFactoryService(new Reference('config.context.factory')) ->setFactoryMethod('get') - ->addMethodCall('setOverride', array($conf)); + ->addArgument('Drupal\Core\Config\Context\GlobalConfigContext') + ->addMethodCall('setGlobalOverride'); $container->register('config.context.admin', 'Drupal\Core\Config\Context\ContextInterface') ->setFactoryService(new Reference('config.context.factory')) diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php index 1dfc9f3..17a8ee5 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigOverrideTest.php @@ -58,7 +58,7 @@ function testConfOverride() { $conf['config_test.system']['foo'] = 'overridden'; $conf['config_test.system']['baz'] = 'injected'; $conf['config_test.system']['404'] = 'derp'; - drupal_container()->get('config.context')->setOverride($conf); + drupal_container()->get('config.context')->setGlobalOverride(); // Verify that the in-memory configuration object still contains the // original data. @@ -98,7 +98,7 @@ function testConfOverride() { // Remove the $conf overrides and reset value in config.context service. unset($conf['config_test.system']); - drupal_container()->get('config.context')->setOverride($conf); + drupal_container()->get('config.context')->setGlobalOverride(); // Reload it and verify that it still contains the original data. $config->init(); diff --git a/core/modules/locale/lib/Drupal/locale/LocaleBundle.php b/core/modules/locale/lib/Drupal/locale/LocaleBundle.php index 4bd8dc0..7c2ca6e 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleBundle.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleBundle.php @@ -22,6 +22,7 @@ class LocaleBundle extends Bundle { public function build(ContainerBuilder $container) { $container->register('locale_config_subscriber', 'Drupal\locale\LocaleConfigSubscriber') ->addArgument(new Reference('language_manager')) + ->addArgument(new Reference('config.context')) ->addTag('event_subscriber'); } diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 79ebbd3..b7b281b 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -8,10 +8,14 @@ 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; use Drupal\Core\Language\LanguageManager; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -28,6 +32,8 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { */ protected $languageManager; + protected $defaultConfigContext; + /** * Constructs a LocaleConfigSubscriber object. * @@ -36,8 +42,9 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { * @param \Drupal\Core\Language\LanguageManager $language_manager * The language manager service. */ - public function __construct(LanguageManager $language_manager) { + public function __construct(LanguageManager $language_manager, ContextInterface $config_context) { $this->languageManager = $language_manager; + $this->defaultConfigContext = $config_context; } /** @@ -77,6 +84,12 @@ public function configLoad(ConfigEvent $event) { } } + public function onKernelRequestSetDefaultConfigContextLocale(GetResponseEvent $event) { + if ($language = $this->languageManager->getLanguage(LANGUAGE_TYPE_INTERFACE)) { + $this->defaultConfigContext->set('locale.language', $language); + } + } + /** * Get configuration name for this language. * @@ -101,6 +114,7 @@ public function getLocaleConfigName($name, Language $language) { static function getSubscribedEvents() { $events['config.context'][] = array('configContext', 20); $events['config.load'][] = array('configLoad', 20); + $events[KernelEvents::REQUEST][] = array('onKernelRequestSetDefaultConfigContextLocale', 20); return $events; } }