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.

Comments

Maouna created an issue. See original summary.

Maouna’s picture

A failing patch for demonstration.

Maouna’s picture

Status: Active » Needs review
hchonov’s picture

Priority: Normal » Major

I 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();

Status: Needs review » Needs work

The last submitted patch, 2: 2859202-referenced_language_failing-2.patch, failed testing.

Maouna’s picture

Priority: Major » Normal
Status: Needs work » Needs review
StatusFileSize
new6.41 KB
Maouna’s picture

Priority: Normal » Major

Status: Needs review » Needs work

The last submitted patch, 6: 2859202-referenced_language_fix-5.patch, failed testing.

Maouna’s picture

Status: Needs work » Needs review
StatusFileSize
new8.75 KB
new2.38 KB

Status: Needs review » Needs work

The last submitted patch, 9: 2859202-referenced_language_fix-9.patch, failed testing.

Maouna’s picture

Status: Needs work » Needs review
StatusFileSize
new9.77 KB
new2.15 KB

Status: Needs review » Needs work

The last submitted patch, 11: 2859202-referenced_language_fix-11.patch, failed testing.

Maouna’s picture

Status: Needs work » Needs review
StatusFileSize
new12.52 KB
new2.43 KB

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

blanca.esqueda’s picture

Version: 8.7.x-dev » 8.6.2
StatusFileSize
new12.54 KB

Updated the patch to apply against Drupal 8.6.2
Tested and it resolved the issue with translatable entities with a parent not translatable.

Status: Needs review » Needs work

The last submitted patch, 17: 2859202-referenced_language_fix-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ytsurk’s picture

hchonov’s picture

Assigned: Maouna » Unassigned
hchonov’s picture

Version: 8.6.2 » 8.8.x-dev

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

drcolossos’s picture

Since 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

drcolossos’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: 2859202-referenced_language_fix-24-9.1.x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sanjayk’s picture

Assigned: Unassigned » sanjayk
sanjayk’s picture

Now I have fixed coding standard issues and now working on test cases. Once fixed I will update here

sanjayk’s picture

Test cases Fixed for both d8 and 9.

sanjayk’s picture

Assigned: sanjayk » Unassigned
Status: Needs work » Needs review

@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

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

golddragon007’s picture

Actually, #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...

martins.bertins’s picture

Re-rolled the patch #29 against 9.2.x.

ranjith_kumar_k_u’s picture

StatusFileSize
new10.65 KB
new2.31 KB

Fixed CS issues

Status: Needs review » Needs work

The last submitted patch, 35: 2859202-35.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

norman.lol’s picture

For 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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.