Host translation shows incorrect translation of embedded entity

Created on 27 February 2020, over 4 years ago
Updated 3 March 2024, 7 months ago

#3018485: Selected Entity should display in host entity's language in EntityEmbedDialog when data-langcode not set introduced new attribute "data-langcode" of drupal-entity element stored in the text fields. Unfortunately, declaring the language of embedded entity creates a problem when new translation is added to the host entity: this attribute is not changed automatically for the translated value of the text field, so human editor has to change it manually.

I suggest not to store this attribute in the text - when the host entity is being rendered, the host entity language is known, and the attribute doesn't add any new information but can create contradictions.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇷🇺Russia maximpodorov

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • Patch created based on #9

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    82 pass, 3 fail
  • 🇭🇺Hungary balagan

    Rerolled the patch, as it didn't apply anymore.

  • Status changed to Needs work about 1 year ago
  • 🇬🇧United Kingdom Baysaa

    Re-rolled above patch which didn't contain the reference to the TranslatableInterface

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    82 pass, 2 fail
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    82 pass, 2 fail
  • 🇨🇦Canada smulvih2 Canada 🍁

    I disagree with the change of approach starting in #6. This new approach is causing tests in ContentTranslationTest to fail, since the data-langcode value doesn't match the embedded entity's language.

    I think the approach in #2 was correct, since this actually fixes the data. If we use a filter to fix this, then the data on non-English languages will still use an incorrect data-langcode value, but the problem is masked while viewing the content. This would cause issues for anyone needing to manipulate the data programmatically and relying on the language code to be correct. I re-rolled #2 to apply against 1.5.0.

    I also modified the ContentTranslationTest test as follows:

    • Do not create a French translation right after the initial entity creation.
    • Save the English node after adding an embedded entity.
    • Go to the add translation route, ensure a element exists with the data-langcode set to "fr".
    • Delete the embedded entity and continue tests with French embedding.

    I'm not very good with tests, so this might need to be adjusted.

Production build 0.71.5 2024