Problem/Motivation

The Paragraphs summary initially shows the wrong language (source) for translation.
This is very confusing as originally it looks like the data is wrong / outdated / untranslated and thus inconsistent.
If you seek to edit a specific Paragraph, it's hard to find it through the summaries.

Then after editing and regenerating the summary, it is updated.
(At the same time the Paragraph then shows the changed indication even if there was no change.)

Proposed resolution
Make sure the summary is generated with consideration of the translation.

User interface changes

Paragraphs summary in the right language.

Data model changes

Comments

miro_dietiker created an issue. See original summary.

miro_dietiker’s picture

I accidentally duplicated this issue, thus promoting with a comment. :-)

merilainen’s picture

Status: Active » Needs review
StatusFileSize
new779 bytes

I think the problem lies in the getNestedSummary() where the referenced entity is fetched but there is nothing language specific.
In my case I do see paragraph values in correct language, but if that paragraph has nested paragraphs, they appear in the summary in the original (source) language.

Here is a patch which seems to fix it.

johnchque’s picture

While testing this I realized that this might work better when there are multiple translation of the node. I will work on the tests tomorrow.
@mErilainen thanks for your patch! :)

Status: Needs review » Needs work

The last submitted patch, 4: 2991941_translated_nested_paragraph_summary-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

merilainen’s picture

StatusFileSize
new44.16 KB

To me it seems that the last patch is trying to fetch the nested paragraph in the parent paragraph's source language, which would not be the translation being edited. And it doesn't work either, see the attached screenshot.

johnchque’s picture

Ohhh I see, then I found a different problem. When we have more than one translation for the node. And we select the source language that we want to translate, when we switch the language, the summary always displays the original language.

Will open an issue for that.

I could replicate what you mean, think your first patch made sense then, working on tests now. :)

merilainen’s picture

So should I add my first patch back here to get it tested?

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new2.51 KB
new3.27 KB

There we go with tests. :) This should avoid regressions later. :)

johnchque’s picture

The last submitted patch, 9: 2991941_translated_nested_paragraph_summary-8-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Paragraph.php
@@ -658,6 +658,11 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
+          if ($entity->hasTranslation($this->activeLangcode)) {
+            // Check if nested paragraph has a translation for the parent
+            // paragraph's language and use that if there is.
+            $entity = $entity->getTranslation($this->activeLangcode);
+          }

Lets also do that for the referenced entities and their label.

Thought about using \Drupal\Core\Entity\EntityRepositoryInterface::getTranslationFromContext(), but I don't think we care about the fallback here. It would save the hasTranslation check though.

johnchque’s picture

True, referenced entities had the same problem. This should fix it. :)

The last submitted patch, 13: 2991941_translated_nested_paragraph_summary-13-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Paragraph.php
@@ -465,7 +465,10 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
+          $entity = $this->get($field_name)->entity;
+          // Switch to the entity translation in the current context if exists.
+          $entity = $this->entityManager()->getTranslationFromContext($entity, $this->activeLangcode);
+          $summary[] = $entity->label();

entityManager() is deprecated, we shouldn't add new usages of that. The problem is that this method moved to a different service, so you can't use entityTypeManager() but have to call out to \Drupal::service()

megadesk3000’s picture

I am starting to work on this on #drupaleurope

megadesk3000’s picture

Changed code to use Drupal::service() instead of entityManager()

megadesk3000’s picture

Status: Needs work » Needs review
johnchque’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Paragraph.php
@@ -658,6 +661,8 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
+          $entity = $this->entityManager()->getTranslationFromContext($entity, $this->activeLangcode);

Let's also change here. :)

megadesk3000’s picture

Changed the other entityManager() occurence as well.

megadesk3000’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work

That's still the wrong service though, you still use the deprecated entity manager.

The service you need to use is entity.repository.

megadesk3000’s picture

Hi @Berdir

You are totally right. Missed that point and fixed it now.

megadesk3000’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Thank you, committed this!

Status: Fixed » Closed (fixed)

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