diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php index 133604df1b314ef54d054fbddaf81b2fe0e4b220..917e591171fb61076e8b3236bbb77855b54ebe31 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php @@ -130,10 +130,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL, } $languages = array_flip(array_keys($this->languageManager->getLanguages())); // Language can be passed as an option, or we go for current URL language. - if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && in_array($options['language']->getId(), [ - LanguageInterface::LANGCODE_NOT_SPECIFIED, - LanguageInterface::LANGCODE_NOT_APPLICABLE, - ]))) { + if (!isset($options['language']) || ($options['language'] instanceof LanguageInterface && $options['language']->getId() == LanguageInterface::LANGCODE_NOT_SPECIFIED)) { $language_url = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL); $options['language'] = $language_url; } diff --git a/core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php b/core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php index a78b36aa07056c118b8406c400e132b1f334cb8d..8eaf87478dda1813b844bf65f9c121fea1e9713e 100644 --- a/core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php +++ b/core/modules/language/tests/src/Unit/LanguageNegotiationUrlTest.php @@ -156,6 +156,71 @@ public function providerTestPathPrefix() { return $path_prefix_configuration; } + /** + * Tests outbound path processing for neutral languages. + * + * @dataProvider providerNeutralLanguages + */ + public function testNeutralLanguages($langcode, $expected_langcode) { + if ($expected_langcode) { + $this->languageManager->expects($this->once()) + ->method('getCurrentLanguage') + ->willReturn($this->languages['en']); + } + + $config = $this->getConfigFactoryStub([ + 'language.negotiation' => [ + 'url' => [ + 'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX, + 'prefixes' => [ + 'de' => 'de', + 'en' => 'en', + ], + ], + ], + ]); + + $request = Request::create('/foo', 'GET'); + $method = new LanguageNegotiationUrl(); + $method->setLanguageManager($this->languageManager); + $method->setConfig($config); + $method->setCurrentUser($this->user); + $this->assertNull($method->getLangcode($request)); + + $language = $this->createMock(LanguageInterface::class); + $language->expects($this->any()) + ->method('getId') + ->willReturn($langcode); + $cacheability = new BubbleableMetadata(); + $options = [ + 'language' => $language, + ]; + $method->processOutbound('foo', $options, $request, $cacheability); + $expected_cacheability = new BubbleableMetadata(); + if ($expected_langcode) { + $this->assertSame($expected_langcode . '/', $options['prefix']); + $expected_cacheability->setCacheContexts(['languages:' . LanguageInterface::TYPE_URL]); + } + else { + $this->assertFalse(isset($options['prefix'])); + } + $this->assertEquals($expected_cacheability, $cacheability); + } + + /** + * Provides data for the neutral language test. + * + * @return array + * An array of data for checking path prefix negotiation for neutral + * languages. + */ + public function providerNeutralLanguages() { + return [ + [LanguageInterface::LANGCODE_NOT_APPLICABLE, NULL], + [LanguageInterface::LANGCODE_NOT_SPECIFIED, 'en'], + ]; + } + /** * Tests domain language negotiation and outbound path processing. * diff --git a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php index b4ea93b0cf7ad22e3ec1d1f6e3274912b72bdd18..c0d36ad10500793261a9e2db8ab01111b74c31eb 100644 --- a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php +++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php @@ -602,7 +602,6 @@ public function testDetailsTitleIsNotEscaped() { public function testUrlPrefixOnLanguageNeutralContent() { $this->drupalLogin($this->administrator); $neutral_langcodes = [ - LanguageInterface::LANGCODE_NOT_APPLICABLE, LanguageInterface::LANGCODE_NOT_SPECIFIED, ]; foreach ($neutral_langcodes as $langcode) {