summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2017-03-09 08:53:13 (GMT)
committerAlex Pott2017-03-09 08:53:13 (GMT)
commitb26016db7a7e02201766e1a319771975e332fffa (patch)
tree5b576b99c42f322aaadd6fe00afff5e11f6a7f06
parentfc2220f79ae23366e1d134a52c7e0b15a6bcf99b (diff)
Issue #2855977 by blazey: LanguageNegotiationUrl::processInbound removes path prefix even when detection is based on domain
-rw-r--r--core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php21
-rw-r--r--core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php77
-rw-r--r--core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php1
3 files changed, 90 insertions, 9 deletions
diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
index 437273b..7436a3f 100644
--- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
+++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationUrl.php
@@ -100,15 +100,18 @@ class LanguageNegotiationUrl extends LanguageNegotiationMethodBase implements In
*/
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;
+ }
}
}
diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php
new file mode 100644
index 0000000..8472ff7
--- /dev/null
+++ b/core/modules/language/tests/src/Functional/LanguageNegotiationUrlTest.php
@@ -0,0 +1,77 @@
+<?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);
+ }
+
+}
diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
index 9e3fcef..57dfbfa 100644
--- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
+++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php
@@ -120,6 +120,7 @@ class PathProcessorTest extends UnitTestCase {
'language.negotiation' => [
'url' => [
'prefixes' => ['fr' => 'fr'],
+ 'source' => LanguageNegotiationUrl::CONFIG_PATH_PREFIX,
],
],
]