Language prefix for custom menu link paths are saved but not used

Created on 30 March 2015, over 9 years ago
Updated 4 April 2023, over 1 year ago

Problem/Motivation

Menu items accept paths with a language but ignore that information when rendering. Steps to reproduce:

1. Install Drupal and have with at least two languages (say English without a path prefix and Norwegian with 'no' as prefix).
2. Create two menu items in main navigation to /node and /no/node. Both are saved.
3. Edit both, they retained what you entered.
4. Go to the front page. Both link to either /node (if page is in English) or /no/node (if page is displayed in Norwegian).

It is expected that they would consider the language entered in the path.

Proposed resolution

Validate the entered path and error if the path is going to be modified by Drupal (e.g. remove language prefix).
The workaround for linking to content in a different language must be using absolute urls.

Remaining tasks

Add a test.

User interface changes

If a url is going to be modified by Drupal on rendering, prevent it and show an error instead of ignoring it (and link to something the user does not expect).

API changes

None.

Beta phase evaluation

🐛 Bug report
Status

Needs work

Version

10.1

Component
Language system 

Last updated 1 day ago

  • Maintained by
  • 🇩🇪Germany @sun
Created by

🇳🇴Norway eiriksm Norway

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • 🇳🇱Netherlands Lendude Amsterdam

    This came up as a bug smash daily triage target.

    Some observations:

    • The validation is now happening at the form level, there are other ways to create menu links (custom code, migrations) but we are not protecting against that
    • The upgrade path is only fixing the menu items at the time of running the update, nothing prevents adding more invalid links. Wouldn't an entity level constraint be better at protecting us here?
    • None of this needs to happen is there are not multiple langagues, but I don't see anything checking for that right?
    • The test coverage seems very slim for the proposed changes.
  • 🇬🇧United Kingdom james.williams

    Just re-rolling to apply to 9.5.x for now. But yes, @Lendude, those look like pretty valid points to address. Thanks for taking the time to review!

  • 🇬🇧United Kingdom steven jones

    Here's a trivially re-rolled patch for 10.2.x

  • 🇬🇧United Kingdom james.williams

    Re-rolled for 10.3. (I don't expect this to get into core any more; it's just most useful for sites needing to upgrade that have been using the previous patches here.)

Production build 0.71.5 2024