Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291503

Multilingual entity reference inside paragraphs unsets values in other translations

$
0
0

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 FieldTranslationSyncronizer.php 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


Viewing all articles
Browse latest Browse all 291503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>