I have two entities that were imported in two translations from another source. When one of these two entities references the other, and I render the parent entity in its non-default translation, the referenced entity is erroneously rendered in its default translation.
The reason is that my entity returns false for isTranslatable(). Therefore, in EntityViewDisplay::buildMultiple the $view_langcode is set to null and in FormatterBase::view $language is set to the current language.
My entity is translatable, it just does not have content_translation enabled. This module is not needed as the actual process of translation is done outside of my site, before the import. Activating content_translation would solve the problem, but is not the correct way.
The way of determing in which language a field is rendered needs to be changed.
| Comment | File | Size | Author |
|---|---|---|---|
| #42 | 2859202-42.patch | 3.2 KB | norman.lol |
| #35 | interdiff_34-35.txt | 2.31 KB | ranjith_kumar_k_u |
| #35 | 2859202-35.patch | 10.65 KB | ranjith_kumar_k_u |
| #34 | 2859202-referenced_language_fix-34-9.2.x.patch | 10.33 KB | martins.bertins |
| #29 | 2859202-referenced_language_fix-29-8.9.x.patch | 9.35 KB | sanjayk |
Comments
Comment #2
Maouna commentedA failing patch for demonstration.
Comment #3
Maouna commentedComment #4
hchonovI think, that this is major as without having enabled content translation for entities even if they are translatable CEB::isTranslatable() will return FALSE and the rendering process depends on it.
@Maouna, could you please adjust the hook, so that it doesn't flag entities not using CT as non-translatable?
So instead
$bundle_info['translatable'] = \Drupal::service('content_translation.manager')->isEnabled($entity_type, $bundle);try
$bundle_info['translatable'] = \Drupal::service('content_translation.manager')->isEnabled($entity_type, $bundle) ?: NULL;CEB::isTranslatable should be adjusted as well to not check with empty but with isset to check the value only if it is set, otherwise ignore it, as this is not a required key.
So instead
return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual();try
return $this->getEntityType()->isTranslatable() && (!isset(($bundles[$this->bundle()]['translatable']) || bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual();Comment #6
Maouna commentedComment #7
Maouna commentedComment #9
Maouna commentedComment #11
Maouna commentedComment #13
Maouna commentedComment #17
blanca.esqueda commentedUpdated the patch to apply against Drupal 8.6.2
Tested and it resolved the issue with translatable entities with a parent not translatable.
Comment #19
ytsurkSounds like #2955392: EntityViewBuilder::viewField() does not respect entity current language when used with an entity reference field
Let's bundle forces there, if the provided patches there help.
Comment #20
hchonovComment #21
hchonovComment #24
drcolossos commentedSince we are running in the same issue and #2949138: Entity Reference Revisions showed always with the default language in blocks. is not resolving it, here is a re-roll for 8.9 and 9.1
Comment #25
drcolossos commentedComment #27
sanjayk commentedComment #28
sanjayk commentedNow I have fixed coding standard issues and now working on test cases. Once fixed I will update here
Comment #29
sanjayk commentedTest cases Fixed for both d8 and 9.
Comment #30
sanjayk commented@Maouna issue already fixed in related issue you can check here and I think this ticket should be closed https://www.drupal.org/project/drupal/issues/2955392
Comment #33
golddragon007 commentedActually, #30 means that this feature needs to be configurable on the UI most probably on the field base for every entity reference. As of now on the project that I'm currently working on we need such behaviour, but on other, we didn't need it...
Comment #34
martins.bertins commentedRe-rolled the patch #29 against 9.2.x.
Comment #35
ranjith_kumar_k_u commentedFixed CS issues
Comment #41
pcambraI've just found this issue while following https://drupal.stackexchange.com/questions/192782/how-do-i-get-views-con...
Patch fixes the issue
Comment #42
norman.lolFor me same as #4, happens always, not only with untranslatable host entity.
Needed a quick workaround. Entity repository in the field formatter and getTranslationFromContext, done.