Do not rely on "content language" in hook_entity_presave()

Created on 14 May 2014, almost 11 years ago
Updated 10 February 2023, about 2 years ago

Problem/Motivation

Currently title_entity_presave() uses title_active_language() which basically relies on the content / interface language set if not actively set otherwise.
This means it works fine for e.g. en/node/1/edit/en because the interface language is the same as the translation language.
However, it fails if de/node/1/edit/en is used even though this is a perfectly fine / allowed / reasonable path to edit a translation (without having to switch the interface language too).
The issue leads to overwritten titles in the interface language.

Proposed resolution

Instead using title_active_language() use the form language of the entity translation handler.
Another approach would have been to use the form language of the entity translation handler only if one is explicitly set, but unfortunately the entity translation handlers (currently) provide no way to check that.

Remaining tasks

See if tests pass - locally I get very random test failures and I can't figure out why (independent if the code base)
I've added a new test which uses another interface language instead the translation language as path prefix. But I don't know yet if this test is valid the way it is.

User interface changes

None.

API changes

None.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇨🇭Switzerland das-peter

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