In the Paragraphs access check we give access to the paragraph depending on the access of the parent entity. However when fetching the parent entity it will always return the entity in the original language. This means that If a user don't have access to the original parent entity, he will not have access to the paragraph in any other language either.

Proposed fix:

Add code that returns the translated parent entity instead, if there is one.

Here is quick patch. There is probably a much cleaner way of doing this though :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

reekris created an issue. See original summary.

reekris’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, load_translated_parent_entity.patch, failed testing.

The last submitted patch, load_translated_parent_entity.patch, failed testing.

The last submitted patch, load_translated_parent_entity.patch, failed testing.

johnchque’s picture

Indeed, the user should be able to get the parent in the correct language.

miro_dietiker’s picture

+++ b/src/Entity/Paragraph.php
@@ -84,7 +84,15 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
+    if ($parent != NULL && method_exists($parent, 'hasTranslation') && $parent->hasTranslation($this->language()->getId())) {

I think we should properly check for TranslatableInterface.

reekris’s picture

Yes, that's a nicer way of checking for translatability. Here is an updated patch.

johnchque’s picture

Status: Needs work » Needs review

Let's see if this breaks something, if not then is time to add tests. :)

Status: Needs review » Needs work

The last submitted patch, 8: load_translated_parent_entity_2.patch, failed testing.

The last submitted patch, 8: load_translated_parent_entity_2.patch, failed testing.

johnchque’s picture

Seems to work, now we just need tests. Test fail is unrelated.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 13: getparententity_does-2790613-13.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review

Unrelated test fail.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

jmuzz’s picture

Status: Needs review » Reviewed & tested by the community

Seems solid. The test only passes with the change to the entity on my installation too.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

The last submitted patch, 13: getparententity_does-2790613-13-test-only.patch, failed testing.

johnchque’s picture

Seems this is still applying.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Also added some comment on getParentEntity documentation.

Status: Fixed » Closed (fixed)

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

james.williams’s picture

Sorry to post on such an old issue here -- but #2854867: getParentEntity() does not respect translation fallbacks is a follow-up to this, and @Berdir has suggested that the Entity Repository service might be better to use, rather than directly loading & getting the translation. Was that considered for this work, and/or are there any good reasons not to?