Skip to content
Snippets Groups Projects
Commit b26016db authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2855977 by blazey: LanguageNegotiationUrl::processInbound removes path...

Issue #2855977 by blazey: LanguageNegotiationUrl::processInbound removes path prefix even when detection is based on domain
parent fc2220f7
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -100,15 +100,18 @@ public function getLangcode(Request $request = NULL) {
*/
public function processInbound($path, Request $request) {
$config = $this->config->get('language.negotiation')->get('url');
$parts = explode('/', trim($path, '/'));
$prefix = array_shift($parts);
// Search prefix within added languages.
foreach ($this->languageManager->getLanguages() as $language) {
if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
// Rebuild $path with the language removed.
$path = '/' . implode('/', $parts);
break;
if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
$parts = explode('/', trim($path, '/'));
$prefix = array_shift($parts);
// Search prefix within added languages.
foreach ($this->languageManager->getLanguages() as $language) {
if (isset($config['prefixes'][$language->getId()]) && $config['prefixes'][$language->getId()] == $prefix) {
// Rebuild $path with the language removed.
$path = '/' . implode('/', $parts);
break;
}
}
}
......
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
/**
* @coversDefaultClass \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl
* @group language
*/
class LanguageNegotiationUrlTest extends BrowserTestBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public static $modules = [
'language',
'node',
'path',
];
/**
* @var \Drupal\user\Entity\User
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create an Article node type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(['type' => 'article']);
}
$this->user = $this->drupalCreateUser([
'administer languages',
'access administration pages',
'view the administration theme',
'administer nodes',
'create article content',
'create url aliases',
]);
$this->drupalLogin($this->user);
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'de'], $this->t('Add language'));
}
/**
* @covers ::processInbound
*/
public function testDomain() {
// Check if paths that contain language prefixes can be reached when
// language is taken from the domain.
$edit = [
'language_negotiation_url_part' => 'domain',
'prefix[en]' => 'eng',
'prefix[de]' => 'de',
'domain[en]' => $_SERVER['HTTP_HOST'],
'domain[de]' => "de.$_SERVER[HTTP_HOST]",
];
$this->drupalPostForm('admin/config/regional/language/detection/url', $edit, $this->t('Save configuration'));
$nodeValues = [
'title[0][value]' => 'Test',
'path[0][alias]' => '/eng/test',
];
$this->drupalPostForm('node/add/article', $nodeValues, $this->t('Save and publish'));
$this->assertSession()->statusCodeEquals(200);
}
}
......@@ -120,6 +120,7 @@ public function testProcessInbound() {
'language.negotiation' => [
'url' => [
'prefixes' => ['fr' => 'fr'],
'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
],
],
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment