Problem description

When having both Language and Domain (country) codes as part of the URL, the language module assumes the first code is the language code. My requirement is to have a URL syntax: /[domain]/[language]/some-page.

The Country Path outbound processor concatenates the $path variable. Other processors, like the Language URL, use the $options['prefix'] variable.

Proposed resolution

It looks like the LanguageNegotiationUrl class is adding/removing a prefix at/from the beginning of the URL. Changing the priority of the Domain inbound and outbound processor to have the CountryPath inbound processor acts first and the outbound processor acts last.

Use $options['prefix'] in the outbound processor.

Comments

jurcello created an issue. See original summary.

jurcello’s picture

jurcello’s picture

Status: Active » Needs review
jurcello’s picture

And now with a working patch.

sutharsan’s picture

I agree with changing the weight of the in and outbound processors. At least for the use case I need it for where the URL structure is example.com/[country]/[language]/. See screenshot for the resulting weights.
Inbound/Outbound path processor weights

But I do not agree with this code:

+    // If prefixes are demanded, handle it here, because the language
+    // for instance will be added later and will then be before the domain prefix.
+    if (!empty($options['prefix'])) {
+      $path = ltrim($path, '/');
+      $prefix = empty($path) ? rtrim($options['prefix'], '/') : $options['prefix'];
+      $path = '/' . str_replace('%2F', '/', rawurlencode($prefix)) . $path;
+      // Unset the prefix from the options, because we already added it.
+      $options['prefix'] = '';
+    }

I presume the purpose of this code is to prefix the $options['prefix'] to the $path. But that contradicts to the comment. Further combining the two is done in the calling code, for example in UrlGenerator::generateFromRoute. If you look at other processors, the path prefix is only put in $options['prefix'] (which is passed by reference). That is what I suggest for this processor to. Just place the country prefix before any of the existing prefixes. The priority will take care of the rest.

In the attached patch, I also remove the assumption that language and the path will never start with the country code. But what is the country code is 'usa' and the original path is also 'usa'. (I know I should have opened a separate issue for this). The CountryPath outbound processor is only called once, so there is no risk of adding the same country code twice.

-    if (!preg_match('/^\/' . $domain_suffix . '/i', $path, $matches)) {
-      $path = '/' . $domain_suffix . $path;
-    }
sutharsan’s picture

Issue summary: View changes
StatusFileSize
new1.53 KB

Reworked the patch to be applied on top of #2790057: Path processor contains hardcoded domain_suffixes which causes non working code, as I need to apply both.

jurcello’s picture

You are right with the prefix. The code looks much cleaner now.

itsekhmistro’s picture

Status: Needs review » Fixed

Hi everyone,

Thank you very much for the patch. Applied.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

nijinanijil’s picture

If country path is there in the url it always returns default language contents .

example.com/us/en/node/1
example.com/us/es/node/1

Both returns English version

johnpicozzi’s picture

I am having an issue where when accessing a path like example.com/apac/de I get redirected to example.com/apac. When looking at the code with Xdebug I see that $options['prefix'] isn't set correctly. If I update the code below manually to replace $options['prefix'] with de/ the site works perfectly.

$options['prefix'] = "$domain_suffix/" . $options['prefix'];

Has anyone else had this issue? trying to find a solution for it.

Country Path - 8.x-1.0
Domain - 8.x-1.0-alpha11
Drupal 8.3.7

iyyappan.govind’s picture

Same issue here also.

quadrexdev’s picture

Hi everyone,

Having the same issue as in #11.

Has anyone found the solution?