Unable to resolve path on node in other language than default

Created on 5 February 2020, almost 5 years ago
Updated 26 January 2023, almost 2 years ago

Problem/Motivation

the decoupled router path in default language (/router/translate-path) can't resolve an alias in another language (i.e. with a language prefix at the beginning of the path argument).

Example:

Given
1) Site with default language of English and another language, German ('de').
2) The alias 'helloworld' is the alias of a node in German that doesn't have an english translation.

You can visit '/de/helloworld' directly in Drupal, but /router/translate-path?path=/de/helloworld doesn't work.

Strangely, if the alias is already resolved, it works.
/router/translate-path?path=/de/node/63 works.

I believe the first one should work too.

Proposed resolution

Detect language prefix and resolve aliases before resolving path.

The bug seems to be within the 'router.no_access_checks' service, which only uses the negotiated language to match the route.

But if we can resolve the path first, then it can find the node's route.

So do this:

    $path = \Drupal::service('path.alias_manager')->getPathByAlias('/helloworld', 'de');
    $router = \Drupal::service('router.no_access_checks');
    $result = $router->match($path);

rather than

    $router = \Drupal::service('router.no_access_checks');
    $result = $router->match('/de/helloworld');

When '/de/node/63' is passed to \Drupal::service('router.no_access_checks') it works, even if the prefix is different than the negotiated language.

If we allow the path.alias_manager to check for alias, then we can get around this bug.

I know you can call the translated decoupled router:
/de/router/translate-path?path=/de/helloworld works.

But it seems inflexible to require the FE devs to call different routes based on the language for the decoupled router. It would be good for the base route to handle paths from any language when using language-url negotiation.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

🇺🇸United States oknate Greater New York City Area

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024