Issue #3385550 by lauriii, Gauravvvv, sboden, Shabbir, longwave: Language negotiation breaks updating Drupal 9 to 10
parent
c4ae1976de
commit
f028872117
|
@ -130,10 +130,7 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
|
|||
}
|
||||
$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;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,71 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
|
|||
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.
|
||||
*
|
||||
|
|
|
@ -602,7 +602,6 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
|
|||
public function testUrlPrefixOnLanguageNeutralContent() {
|
||||
$this->drupalLogin($this->administrator);
|
||||
$neutral_langcodes = [
|
||||
LanguageInterface::LANGCODE_NOT_APPLICABLE,
|
||||
LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
];
|
||||
foreach ($neutral_langcodes as $langcode) {
|
||||
|
|
Loading…
Reference in New Issue