The language of content entities incorrectly falls back to the default language of the content whilst ignoring the current language of the user

Created on 14 June 2019, over 5 years ago
Updated 12 March 2024, 10 months ago

Problem/Motivation

The ::toUrl() method of any content entity seems to incorrectly fall back to the default language of the entity instead of falling back to the language provided by the Language Negotiation API.

In a default scenario (aka when enabling multiple languages on a vanilla Drupal installation) the Language Negotiation API would fall back to the user's current language, which would be reflected by the URL of the page the user is visiting (language domain or prefix).

Currently however, the Entity API is falling back to the default language of the entity, without consulting the Language Negotiation API, resulting in unexpected (and faulty IMHO) behaviour that any URL provided by ::toUrl() will have the language prefix removed (in the default scenario). Clicking on any link generated by ::toUrl() would undesirably change the user's current language. This problem was reported in the following issues:

Proposed resolution

I think this should be solved by changing the way the language of the entity is resolved in the ContentEntityBase::toUrl() method. Instead of defaulting to the entities' default language, it should use Language Negotiation to see what it needs to do.

Remaining tasks

Write tests for all 'child' issues?

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 16 hours ago

Created by

πŸ‡ͺπŸ‡ΈSpain nuez Madrid, Spain

Live updates comments and jobs are added and updated live.
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.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡§πŸ‡ͺBelgium Jonasanne

    Rerolled patch to 10.2.x

  • last update about 1 year ago
    Custom Commands Failed
  • πŸ‡ΊπŸ‡ΈUnited States Greg Boggs Portland Oregon

    This patch only works with the following conditions:

    1. You set your content language the same as your Interface language. So, you have to translate both the admin interface and the content. If your users have a different language for the admin interface, this patch doesn't work for them.

    2. If a content type does not have translation enabled, this patch does not work and it should. Even if a node is not translatable, it still has a valid path in each language and that path should be used to prevent an untranslated node from switching a user's chosen language.

  • πŸ‡ΊπŸ‡ΈUnited States Greg Boggs Portland Oregon

    Here's a patch of the latest work in the MR

Production build 0.71.5 2024