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

Comments

mohit_aghera created an issue. See original summary.

mohit_aghera’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

bladedu’s picture

Status: Needs review » Needs work

Patch doesn't apply on Drupal 8.9.13.

kishor_kolekar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

here is the patch for 8.9.x
please review

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
ranjith_kumar_k_u’s picture

StatusFileSize
new1.39 KB

Rerolled #8 for 9.4.

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

As a bug will need a test case

did not test.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.