Problem

On a regular page load in Drupal 8, the system currently never enters a new context. However, the config context system starts out with a blank slate and if locale module is enabled, it reacts to the Kernel request event and take the language negotiation results into the context. It does not clear the context's override cache, so any config loaded prior to that will not be override-able. Such as the site name for a very trivial example.

Reproduce manually

- Install http://drupal.org/project/config_translation
- Add at least one foreign language
- Translate your site name (Regional and language > Configuration translation > Site information > Translate) to the desired language
- Switch the page to said desired language
- Site name will not be translated

Propposed solution

1. Re-initialize the context when such a crucial thing changes about it as its language. The user context already re-initializes the context when an account is set on it.
2. Make re-initializing the context clear the existing overrides cache on the context.

Note that this also let us remove some duplicate code, since we can actually reuse the existing configContext() response logic, which re-initializing the context will fire.

Files: 
CommentFileSizeAuthor
#18 13-18-interdiff.txt633 bytesalexpott
#18 1934964.config-context-reinit.18.testonly.patch2.57 KBalexpott
FAILED: [[SimpleTest]]: [MySQL] 53,181 pass(es), 1 fail(s), and 0 exception(s). View
#18 1934964.config-context-reinit.18.patch4.25 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 53,236 pass(es). View
#16 13-15-interdiff.txt1.67 KBalexpott
#16 1934964.config-context-reinit.15.patch4.25 KBalexpott
FAILED: [[SimpleTest]]: [MySQL] 53,090 pass(es), 1 fail(s), and 0 exception(s). View
#13 1934964.config-context-reinit.13.testonly.patch1.96 KBalexpott
FAILED: [[SimpleTest]]: [MySQL] 53,155 pass(es), 1 fail(s), and 0 exception(s). View
#13 1934964.config-context-reinit.13.patch3.99 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 53,138 pass(es). View
#10 1934964.config-context-reinit.10.testonly.willfail.patch2.27 KBalexpott
FAILED: [[SimpleTest]]: [MySQL] 52,801 pass(es), 2 fail(s), and 0 exception(s). View
#10 1934964.config-context-reinit.10.patch3.96 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 52,857 pass(es). View
#8 1934964_re-init-context-on-kernel-language-change.patch1.71 KBnevergone
FAILED: [[SimpleTest]]: [MySQL] Setup environment: Test cancelled by admin prior to completion. View
#5 re-init-context-on-kernel-language-change-just-tests.patch2.14 KBGábor Hojtsy
PASSED: [[SimpleTest]]: [MySQL] 52,451 pass(es). View
#4 re-init-context-on-kernel-language-change-error.png61.21 KBandymartha
#4 re-init-context-on-kernel-language-change-success.png61.84 KBandymartha
re-init-context-on-kernel-language-change.patch1.67 KBGábor Hojtsy
PASSED: [[SimpleTest]]: [MySQL] 52,562 pass(es). View

Comments

Gábor Hojtsy’s picture

Status: Active » Needs review
Issue tags: +Needs tests

Needs tests. Settings needs review for bot.

Gábor Hojtsy’s picture

Issue tags: +sprint
vijaycs85’s picture

Applied patch and checked the translation strings with config_translation module. Patch in #1 fixes the problem.

andymartha’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
61.84 KB
61.21 KB

I can confirm that after taking these steps on a Drupal 8.x-dev download from March 6, 2013:
- Install http://drupal.org/project/config_translation
- Add at least one foreign language
- Translate your site name (Regional and language > Configuration translation > Site information > Translate) to the desired language
- Switch the page to said desired language
- Site name will not be translated

and after applying the patch from #1 the problem was fixed and the site was translated.
See attached screenshots.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.14 KB
PASSED: [[SimpleTest]]: [MySQL] 52,451 pass(es). View

Thanks for cross-testing manually. I think it would be very valuable to have automated tests for this. I tried to whip together something but it does not fail! I cannot really figure out why. Anybody have insights? Based on what we do manually to reproduce the issue, the test should fail, right? No?

Gábor Hojtsy’s picture

BTW the reason we did not have tests for this is that all the config override tests (including locale) are unit test based, so they are not meant / targeted to test the full cycle of an override getting into the output of the webpage. That is why I needed to open a totally new webtestbase based test.

alexpott’s picture

Yep #1934712: Merge system.timezone config object into system.date proves we have the issue... once system.timezone is merged into system.date we can no longer localise date and times :(

nevergone’s picture

FileSize
1.71 KB
FAILED: [[SimpleTest]]: [MySQL] Setup environment: Test cancelled by admin prior to completion. View

#0 patch re-rerolled.

Gábor Hojtsy’s picture

Issue tags: +SprintWeekend2013

I've seen @nevergone reproduce the bug and express his joy seeing it fixed with the patch BTW :) That does not save us from needing to produce a failing test :) Also adding #SprintWeekend tag for sprint weekend.

alexpott’s picture

Issue tags: -SprintWeekend2013
FileSize
3.96 KB
PASSED: [[SimpleTest]]: [MySQL] 52,857 pass(es). View
2.27 KB
FAILED: [[SimpleTest]]: [MySQL] 52,801 pass(es), 2 fail(s), and 0 exception(s). View

Here is a failing test and patch with the fix and test... only system.performance, system.file and system.timezone are read before language negotiation... that's why the system.site test does not work.

alexpott’s picture

Issue tags: +SprintWeekend2013

Fixing tags :)

Gábor Hojtsy’s picture

Status: Needs review » Needs work
+++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.phpundefined
@@ -0,0 +1,53 @@
+  /**
+   * Tests translating the site name.
+   */
+  function testSiteNameTranslation() {

The name of the method is not good anymore :)

+++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.phpundefined
@@ -0,0 +1,53 @@
+    config('system.timezone')->set('user.configurable', TRUE)->save();

There is no explanation why you do this?!

+++ b/core/modules/config/lib/Drupal/config/Tests/ConfigLocaleOverrideWebTest.phpundefined
@@ -0,0 +1,53 @@
+    // The English regional settings page should not have a default timezone of
+    // Europe/Paris.
+    $this->drupalGet('admin/config/regional/settings');
+    $this->assertNoOptionSelected('edit-date-default-timezone', 'Europe/Paris');
+
+    // The French regional settings page should have a default timezone of
+    // Europe/Paris.
+    $this->drupalGet('fr/admin/config/regional/settings');
+    $this->assertOptionSelected('edit-date-default-timezone', 'Europe/Paris');

This is pretty odd. If the admin page shows the localised version of the setting, that would be a problem. The regular admin pages should not show localised settings at any time. (Date formats have some custom implementation for this for some reason, but the rest of the forms should use the override free context).

So testing for this actually exposes the bug that overrides are actually used on this form. The prior test I did did not use the admin forms, but instead see the effect on frontend output.

Is there another setting we can test with that has an easily testable frontend effect? I've seen people reproduce the site name issue and I reproduced and debugged it myself. So it is strange it would not be useful in the test...

alexpott’s picture

Status: Needs work » Needs review
FileSize
3.99 KB
PASSED: [[SimpleTest]]: [MySQL] 53,138 pass(es). View
1.96 KB
FAILED: [[SimpleTest]]: [MySQL] 53,155 pass(es), 1 fail(s), and 0 exception(s). View

Hmmm... okay managed to get a failing test by adding

+    // The log in block on the front page appears to use the system.site config
+    // object before language negotiation is finalized.
+    $this->drupalLogout();

to the test.

This should resolve @Gaborhojtsy's objections form #12 as it's now using his system.site override test.

alexpott’s picture

Okay... found the first use of system.site... it's PathProcessorFront::processInbound() and this is called before language is negotiated. Will update code comment.

Gábor Hojtsy’s picture

Status: Needs review » Needs work

Make sense :) Thanks for keeping it to the site name override, which is the most natural example to work with :) Only found two issues.

+++ b/core/lib/Drupal/Core/Config/Context/ConfigContext.phpundefined
@@ -63,6 +63,8 @@ public function __construct(EventDispatcher $event_dispatcher) {
+    // // Reset existing overrides and get a UUID for this context.
+    $this->overrides = array();

Too much // :D

Also core/modules/config/tests/config_test/config/locale.config.fr.system.site.yml missing from both test only and the other patch.

alexpott’s picture

Status: Needs work » Needs review
FileSize
4.25 KB
FAILED: [[SimpleTest]]: [MySQL] 53,090 pass(es), 1 fail(s), and 0 exception(s). View
1.67 KB

Updated comment to reflect discoveries...

Gábor Hojtsy’s picture

Status: Needs review » Needs work

#15 problems still stand.

alexpott’s picture

Status: Needs work » Needs review
FileSize
4.25 KB
PASSED: [[SimpleTest]]: [MySQL] 53,236 pass(es). View
2.57 KB
FAILED: [[SimpleTest]]: [MySQL] 53,181 pass(es), 1 fail(s), and 0 exception(s). View
633 bytes

And finally (hopefully) a correct working and failing patch...

Gábor Hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me now :) The fix wil also make #1934712: Merge system.timezone config object into system.date work where another failing test reproduces the issue, so that should be two great reasons to commit :)

Gábor Hojtsy’s picture

Gábor Hojtsy’s picture

Gábor Hojtsy’s picture

Priority: Normal » Major

Upping to major since even though you can save translations for your site name and other basic things, they will never be used on display until this is fixed.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Well that definitely seems sub-optimal.

Committed and pushed to 8.x. Thanks!

Gábor Hojtsy’s picture

Issue tags: -sprint

Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.