Is it correct to say that when embedding an entity in a field on a parent entity, the embedded entity should be rendered in the same translation language as the parent (if available)?

Currently it seems data-langcode is set correctly in $context but not applied to translate the embedded entity. Patch attached translates the entity as part of EntityEmbedBuilder->buildEntityEmbed(). There's a @todo comment relating to deciding what to do if the embedded entity has no translation in the parent's language - perhaps this could be a configurable setting? i.e. display base language entity, or hide?

Comments

bgilhome created an issue. See original summary.

bgilhome’s picture

bgilhome’s picture

Issue summary: View changes
wim leers’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2576983: Add tests to ensure translated content works as expected

This is already fixed in HEAD and comes with test coverage, since #2576983: Add tests to ensure translated content works as expected :) The next release will ship with this!

wim leers’s picture

Title: Translate embedded entity to parent's language if available » Ignore `data-langcode` if that translation does not exist; instead use the host entity's language
Priority: Normal » Major
Status: Closed (duplicate) » Needs work
Issue tags: +D8MI, +Needs tests

I was a tad too fast, because the issue title doesn't match what the patch is doing!

Clarified title, now what is still needed is test coverage.

Great find! (And another clear reason we need more test coverage in this module.)

wim leers’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.13 KB

Actually, this is working fine.

I understand this observation:

Currently it seems data-langcode is set correctly in $context but not applied to translate the embedded entity.

… it's because it's not \Drupal\entity_embed\EntityEmbedBuilder that does the loading of the translation, that's up to to the individual @EntityEmbedDisplay plugins.

Attached is test coverage that passes against HEAD (at least locally).

wim leers’s picture

Title: Ignore `data-langcode` if that translation does not exist; instead use the host entity's language » Add tests to ensure `data-langcode` works when that translation does not exist; should fall back to default translation
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new2.19 KB
new3.02 KB

  • Wim Leers committed c4f496c on 8.x-1.x
    Issue #3027445 by Wim Leers, bgilhome: Add tests to ensure `data-...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.