Multilingual entity reference inside paragraphs unsets values in other translations

Created on 11 December 2017, almost 7 years ago
Updated 20 February 2023, over 1 year ago

Problem/Motivation

When some media entity is entity referenced inside nested paragraphs and we try to add translation of media entity during node edit,
it will unset original language's media field value.

Let's say we have "Image" and "Image Item" paragraphs.
"Image item" paragraph's is added inside image paragraph.

Field structure for "Image" paragraph is something like given below:
Title
Image Items (paragraphs reference to "image item" paragraphs)

Field structure for "Image Item" paragraph is given below:
Title
Image (Media reference field, pointing to image bundle of media entity)

For one page content type,
Add one paragraph reference field and set that it allows to add "Image" paragraphs.
Enable multi-lingual support, enable translation support for page, and paragraph items(title and other fields).

Create page node.
Add "Image" paragraph content,
which will also force you to add "Image item" paragraph content, because it is embedded inside "Image" paragraph.
Attach some media entity.
Save node.

Add translation of page node
Click on "Image" and "Image item" paragraphs to add it's translations
Attach some different media entity.
Save the form.

If you see the original node's form, media reference value of "Image item" field be reset and NULL.

Proposed resolution

Currently In file:
Line 95-98

foreach ($translations as $langcode => $language) {
    $entity->getTranslation($langcode)->get($field_name)->setValue($values[$langcode]);
}

We can check and ensure that "$values[$langcode]" exists before doing setValue() function.

foreach ($translations as $langcode => $language) {
   if (isset($values[$langcode])) {
      $entity->getTranslation($langcode)->get($field_name)->setValue($values[$langcode]);
      }
 }

so that it won't save null value in original translations considering that it has already values set.

Moreover, we are already filtering in line 143 that $values should return values of the language which is currently being edited. So it will never return field's original language.
if ($langcode != $sync_langcode) {

Remaining tasks

Write test cases to reproduce issue.

User interface changes

No changes.

API changes

No changes.

Data model changes

🐛 Bug report
Status

Needs work

Version

9.5

Component
Content translation 

Last updated about 19 hours ago

No maintainer
Created by

🇮🇳India mohit_aghera Rajkot

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.

Production build 0.71.5 2024