Problem/Motivation

I have content type with paragraph reference field.
I can create node with en-int original language and de translation
Then if I want to create de-DE translation based on de, I can select translation source language on translation edit form. In such case new translation will be based on selected language, but paragraph translations are based on original language.

Steps to reproduce

  1. Create translatable paragraph type
  2. Create translatable content type with paragraph reference field
  3. Enable content moderation for the content type
  4. Enable 3 languages
  5. Create node with default language 1
  6. Add translation to language 2 and translate paragraphs too
  7. Add translation to language 3 based on language 2
  8. Check if default values of paragraph widget based on language 1 translation

Proposed resolution

In entity_reference_revisions_entity_revision_create we can check if entity has content_translation_source field and try to load source language translation of the target entity to use as source for new translation

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vladimir.krupin created an issue. See original summary.

vladimir.krupin’s picture

kala4ek’s picture

Version: 8.x-1.9 » 8.x-1.11
StatusFileSize
new1.48 KB

Updated patch to be applicable for 1.11 version.

kala4ek’s picture

StatusFileSize
new1.82 KB

Updated patch that works with nested paragraphs too.

nikolay shapovalov’s picture

Version: 8.x-1.11 » 8.x-1.x-dev
Status: Active » Needs work
Issue tags: +Needs tests

Thanks for your patches, but please use MR approach instead of patch.
You can update existing MR #12, or create new one.
And it would be great if you can provide functional test to cover this issue.

nikolay shapovalov changed the visibility of the branch 8.x-1.x to hidden.

nikolay shapovalov’s picture

I tried to replicate this issue, and I wasn't able.
Drupal 11 latest, paragraphs latest.
On step 6, I have dropdown "Source language: language 1" and I can change source from language 1 (default value) to language 2.
Then values from language 2 translation used.

Can you please provide more information?
Did you mark field node->paragraph translatable?

I found at documentation page:

Never enable translation on the Paragraphs field (Entity reference revisions), as it will enable adding new paragraphs while translating, even if an empty field (not containing any paragraph field) is on the translation source node - which is not supported!

And test Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTranslationTest::testParagraphTranslation() covers similar logic.

refs made their first commit to this issue’s fork.

refs’s picture

I tried to replicate this issue, and I wasn't able.
Drupal 11 latest, paragraphs latest.

Unfortunately, I don't currently have a Drupal 11 system to test it on, but I have installed various Drupal 10.5 systems with the latest Paragraphs (1.19), entity_reference_revisions 1.12 and the patch from #4 to fix this issue.

Now a customer has pointed out to me that it doesn't work with nested paragraphs. Patch #5 doesn't work with multiple nested paragraphs. For this reason, I have adapted the patch so that the parent that has also set a content source is now taken into account. As a rule, this should probably be the root/node.

Can you please provide more information?
Did you mark field node->paragraph translatable?

Let's assume I have languages A, B, and C in the system. I create a node with a text paragraph in language A. I translate the node and its content into language B. So far, everything is correct. Now I want to translate the node into language C. Language A is selected as the source language by default, as it is the default language of the node, and everything is fine in the initial form. However, if I switch to language B as the content source, the content of the paragraphs continues to be output in language A. The problem exists both at the first level of paragraphs and at the nested level.

My paragraph fields are not translatable

And test Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTranslationTest::testParagraphTranslation() covers similar logic.

I believe that the test only checks the language of the paragraph in the edit form step and not the initial content. The language of the paragraphs is always the language of the newly created translation and is correct.

refs’s picture

Status: Needs work » Needs review

marcusml made their first commit to this issue’s fork.

marcusml’s picture

Title: Content translation source is not taken into account for paragraphs in case of translation of host entity. » Content translation source is not taken into account for paragraph when host uses content moderation
Issue summary: View changes
Issue tags: -Needs tests

We just experienced the same issue on our site.

I was not able to reproduce it without content moderation enabled on the host entity. Maybe that was the case for @nikolay shapovalov in #18?

I've rebased the current branch and pushed a new approach where instead of crawling up the host entity we set the content_translation_source on the composite entities instead, and create translations based on that.

Added test for this as well.

marcusml’s picture

Assigned: Unassigned » marcusml
Status: Needs review » Needs work

Taking a look at the test failures.

marcusml’s picture

Assigned: marcusml » Unassigned
Status: Needs work » Needs review

I see the test failure was unrelated and on the main branch as well.

I've run the test-only job which expectedly fails. The result is available here: https://git.drupalcode.org/issue/entity_reference_revisions-3295973/-/pi...

berdir’s picture

Status: Needs review » Needs work

Reviewed.

marcusml’s picture

Status: Needs work » Needs review

Thanks for the review. 🙏

I've addresses the feedback and it's now back for review again.

berdir’s picture

Status: Needs review » Needs work

This conflicts and needs to be rebased.

marcusml’s picture

Status: Needs work » Needs review

I've rebased on top of 8.x-1.x. Some jobs are failing but looks to be present on main branch as well. Back to review.

berdir’s picture

Status: Needs review » Fixed

Thanks for sticking with this, merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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