Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 :)
Comment | File | Size | Author |
---|---|---|---|
#13 | getparententity_does-2790613-13.patch | 3.29 KB | johnchque |
#13 | getparententity_does-2790613-13-test-only.patch | 1.96 KB | johnchque |
#8 | load_translated_parent_entity_2.patch | 1.33 KB | reekris |
load_translated_parent_entity.patch | 942 bytes | reekris | |
Comments
Comment #2
reekris CreditAttribution: reekris commentedComment #6
johnchqueIndeed, the user should be able to get the parent in the correct language.
Comment #7
miro_dietikerI think we should properly check for TranslatableInterface.
Comment #8
reekris CreditAttribution: reekris commentedYes, that's a nicer way of checking for translatability. Here is an updated patch.
Comment #9
johnchqueLet's see if this breaks something, if not then is time to add tests. :)
Comment #12
johnchqueSeems to work, now we just need tests. Test fail is unrelated.
Comment #13
johnchqueTests added. Interdiff = Test only.
Comment #18
johnchqueUnrelated test fail.
Comment #23
jmuzz CreditAttribution: jmuzz commentedSeems solid. The test only passes with the change to the entity on my installation too.
Comment #27
johnchqueSeems this is still applying.
Comment #29
miro_dietikerCommitted.
Also added some comment on getParentEntity documentation.
Comment #31
james.williams CreditAttribution: james.williams at ComputerMinds commentedSorry 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?