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, about 6 years ago
Updated 30 January 2023, over 2 years 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

10.1

Component
Entity 

Last updated 1 day 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.

Production build 0.71.5 2024