diff --git a/core/modules/language/src/ConfigurableLanguageManager.php b/core/modules/language/src/ConfigurableLanguageManager.php index 238bd83..c21377d 100644 --- a/core/modules/language/src/ConfigurableLanguageManager.php +++ b/core/modules/language/src/ConfigurableLanguageManager.php @@ -92,9 +92,9 @@ class ConfigurableLanguageManager extends LanguageManager implements Configurabl /** * Whether already in the process of language initialization. * - * @var bool + * @var array */ - protected $initializing = FALSE; + protected $initializing = []; /** * {@inheritdoc} @@ -212,13 +212,18 @@ public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE) { // Ensure we have a valid value for this language type. $this->negotiatedLanguages[$type] = $this->getDefaultLanguage(); + // Ensure that the initalizing array is properly set up for any keys. + if (!isset($this->initializing[$type])) { + $this->initializing[$type] = FALSE; + } + if ($this->negotiator && $this->isMultilingual()) { - if (!$this->initializing) { - $this->initializing = TRUE; + if (!$this->initializing[$type]) { + $this->initializing[$type] = TRUE; $negotiation = $this->negotiator->initializeType($type); $this->negotiatedLanguages[$type] = reset($negotiation); $this->negotiatedMethods[$type] = key($negotiation); - $this->initializing = FALSE; + $this->initializing[$type] = FALSE; } // If the current interface language needs to be retrieved during // initialization we return the system language. This way string diff --git a/core/modules/language/src/Tests/LanguageContentNegotiationTest.php b/core/modules/language/src/Tests/LanguageContentNegotiationTest.php new file mode 100644 index 0000000..4e7acf2 --- /dev/null +++ b/core/modules/language/src/Tests/LanguageContentNegotiationTest.php @@ -0,0 +1,102 @@ +drupalCreateUser($permissions); + $this->drupalLogin($user); + + // Add a language + $edit = [ + 'predefined_langcode' => 'fr', + ]; + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + } + + /** + * Ensure that the edit links point to the right language. + */ + function testContentNegotiation() { + // Set browser detection for interface and session for content. + $edit = [ + 'language_interface[enabled][language-url]' => FALSE, + 'language_interface[enabled][language-browser]' => TRUE, + 'language_content[configurable]' => TRUE, + 'language_content[enabled][language-session]' => TRUE, + 'language_content[enabled][language-interface]' => FALSE, + ]; + $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings')); + + // Make page nodes translatable. + $edit = [ + 'entity_types[node]' => 1, + 'settings[node][page][translatable]' => 1, + 'settings[node][page][settings][language][language_alterable]' => 1, + ]; + $this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration')); + + // Create a node. + $node = $this->drupalCreateNode(['type' => 'page', 'langcode' => 'en']); + + // Translate the node. + $edit = [ + 'title[0][value]' => $this->randomMachineName(), + 'body[0][value]' => $this->randomMachineName(), + ]; + $this->drupalPostForm('node/' . $node->id() . '/translations/add/en/fr', $edit, t('Save (this translation)')); + + // Click on the first edit link on the translate tab (English). + $this->drupalGet('node/' . $node->id()); + $this->clickLink('Translate'); + $this->clickLink('Edit', 1); + + // Ensure that this is the English node. + $this->assertText($node->body->value); + + // Click on the second edit link on the translate tab (French). + $this->drupalGet('node/' . $node->id()); + $this->clickLink('Translate'); + $this->clickLink('Edit', 2); + + // Ensure that this is the French translation. + $this->assertNoText($node->body->value); + } + +}