Problem/Motivation

If the route matcher service is used and a language-prefixed path alias is passed to it, then the language inbound processor will remove the langcode of the path and the path will be passed to the path alias manager without a langcode. That creates an issue if the same path alias is configured for two different pages for two different languages and we will never be able to correctly route one of the paths. See "Steps to reproduce" for an use case with the menu system.

Steps to reproduce

1. Create two nodes - one in English and one in German and setup for both the path alias "my-path-alias".
2. Configure your site to use language detection with path prefixes - en and de respectively.
3. Create two main navigation menus - one for English and one for German.
4. While on the English language page - example.com/en - create one menu item in both of the menus and use en/my-path-alias and de/my-path-alias respectively for the link.
5. Observe that on the menu overview page for German the link for the menu item is pointing to the English node.

The only workaround is to always create/edit menu items for a specific language only while being on the page for that language. Or in another words create/edit menu items for the German menu only while being on example.com/de and not on example.com/en.

Proposed resolution

1. When the LanguageNegotiationUrl inbound path processor strips down the language prefix it should add it as an attribute on the request object.
2. The AliasPathProcessor inbound path processor should use the langcode set on the request when querying the path.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3314941

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

hchonov created an issue. See original summary.

hchonov’s picture

Status: Active » Needs review
StatusFileSize
new1.88 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3314941-2.patch, failed testing. View results

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

seanb’s picture

This doesn't seem to fix the following use case:

  • Add the Dutch language (default, no prefix) and English language (with a /en prefix).
  • Edit a Dutch node, linking to a different Dutch page using the English admin language.
  • When a module calls PathValidator::getUrlIfValidWithoutAccessCheck() for the link, you run into the same issue.

Found this while looking at #3427893: processUrl Cannot Find the Correct Entity in Multilingual Site.
We could use the language with an empty language prefix as the default langcode. I think that should fix the issue.

seanb’s picture

Status: Needs work » Needs review
StatusFileSize
new1.82 KB
new2.58 KB

Attached is a patch that seems to solve the issue.

needs-review-queue-bot’s picture

Status: Needs review » Needs work

The Needs Review Queue Bot tested this issue.

While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)

dspachos’s picture

StatusFileSize
new3.22 KB

Patch enhanced to cover also the getUrlIfValidWithoutAccessCheck()

jhuhta’s picture

#9: I think we should inject the language manager instead of calling \Drupal::languageManager() if this change is necessary. And continue from the previous merge request too.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.