From dd927b00083c96dd4255f68c51b3030282311586 Mon Sep 17 00:00:00 2001 From: webchick Date: Sun, 17 Mar 2013 12:24:33 -0700 Subject: [PATCH] =?UTF-8?q?Issue=20#1934964=20by=20alexpott,=20G=C3=A1bor?= =?UTF-8?q?=20Hojtsy,=20nevergone:=20Fixed=20Locale=20override=20subscribe?= =?UTF-8?q?r=20should=20re-init=20context=20to=20clear=20caches.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Config/Context/ConfigContext.php | 2 + .../Tests/ConfigLocaleOverrideWebTest.php | 60 +++++++++++++++++++ .../config/locale.config.fr.system.site.yml | 1 + .../Drupal/locale/LocaleConfigSubscriber.php | 8 ++- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php create mode 100644 core/modules/config/tests/config_test/config/locale.config.fr.system.site.yml diff --git a/core/lib/Drupal/Core/Config/Context/ConfigContext.php b/core/lib/Drupal/Core/Config/Context/ConfigContext.php index ab2ac548a0e..a5382fdb68c 100644 --- a/core/lib/Drupal/Core/Config/Context/ConfigContext.php +++ b/core/lib/Drupal/Core/Config/Context/ConfigContext.php @@ -63,6 +63,8 @@ class ConfigContext implements ContextInterface { * 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); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php new file mode 100644 index 00000000000..9f9579d0ff3 --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.php @@ -0,0 +1,60 @@ + 'Locale overrides through the request', + 'description' => 'Tests locale overrides applied through the website.', + 'group' => 'Configuration', + ); + } + + function setUp() { + parent::setUp(); + } + + /** + * Tests translating the site name. + */ + function testSiteNameTranslation() { + $adminUser = $this->drupalCreateUser(array('administer site configuration', 'administer languages')); + $this->drupalLogin($adminUser); + + // Add French and make it the site default language. + $this->drupalPost('admin/config/regional/language/add', array('predefined_langcode' => 'fr'), t('Add language')); + + $this->drupalLogout(); + + // The home page in English should not have the override. + $this->drupalGet(''); + $this->assertNoText('French 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. The config_test module includes a + // locale.config.fr.system.site.yml which overrides the site name to 'French + // site name' to test that the configuration factory is re-initialised + // language negotiation. Ensure that it applies when we access the French + // front page. + // @see \Drupal\Core\PathProcessor::processInbound() + $this->drupalGet('fr'); + $this->assertText('French site name'); + } + +} diff --git a/core/modules/config/tests/config_test/config/locale.config.fr.system.site.yml b/core/modules/config/tests/config_test/config/locale.config.fr.system.site.yml new file mode 100644 index 00000000000..0e4081b0426 --- /dev/null +++ b/core/modules/config/tests/config_test/config/locale.config.fr.system.site.yml @@ -0,0 +1 @@ +name: 'French site name' diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 5a85399f98f..3f0d99be0cd 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -99,9 +99,11 @@ class LocaleConfigSubscriber implements EventSubscriberInterface { * Kernel event to respond to. */ public function onKernelRequestSetDefaultConfigContextLocale(GetResponseEvent $event) { - if ($language = $this->languageManager->getLanguage(LANGUAGE_TYPE_INTERFACE)) { - $this->defaultConfigContext->set('locale.language', $language); - } + // 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(); } /**