ContentEntityInterface::getTranslation() should throw an exception when an invalid language is specified

Created on 17 September 2013, almost 11 years ago
Updated 12 September 2023, 12 months ago

Problem/Motivation

ContentEntityInterface::getTranslation() returns a new translation if the specified language is valid but there's no corresponding translation for it yet. This is not ideal, we should be creating new translations explicitly. Moreover this has also performance implications, since ContentEntityInterface::addTranslation() is slow (see also #2382675: hook_entity_create() affects the data of new translations of existing entities in unexpected and undocumented ways ).

Proposed resolution

Remove the ContentEntityInterface::addTranslation() invocation from ContentEntityInterface::getTranslation().

Remaining tasks

  • Figure out what's the desired behavior when LanguageInterface::LANGUAGE_NOT_SPECIFIED is passed.
  • Reviews

User interface changes

None

API changes

Yes

Data model changes

None

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
🐛 Bug report
Status

Fixed

Version

8.0 ⚰️

Component
Entity 

Last updated about 13 hours ago

Created by

🇨🇭Switzerland Berdir Switzerland

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

    It affects performance. It is often combined with the Needs profiling tag.

  • API change

    Changes an existing API or subsystem. Not backportable to earlier major versions, unless absolutely required to fix a critical bug.

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