getTranslationLanguages() does not return all translations in case of missing language

Created on 15 March 2019, almost 6 years ago
Updated 23 February 2023, almost 2 years ago

Problem/Motivation

I've just ran into a problem where I am loading entities for which the languages are not anymore activated in the system. When I call getTranslationLanguages() then only the subset of translation languages is returned, for which the language is activated in the system.

I would say that it is our problem if we run into such a situation, however there is this interesting code in \Drupal\Core\Entity\ContentEntityBase::getLanguages():

// If the entity references a language that is not or no longer available,
// we return a mock language object to avoid disrupting the consuming
// code.
if (!isset($this->languages[$this->defaultLangcode])) {
  $this->languages[$this->defaultLangcode] = new Language(['id' => $this->defaultLangcode]);
}

I think that in order to be consistent we should not differentiate between a language being default or non-default when deciding whether to return a mock object or not for it if it does not exist.

Proposed resolution

Return mock language objects for non-existing translation languages already present on the entity.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

10.1

Component
Entity 

Last updated about 9 hours ago

Created by

🇩🇪Germany hchonov 🇪🇺🇩🇪🇧🇬

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