drupal_entity works incorrect when the source content is unpublished

Created on 1 December 2023, 12 months ago
Updated 20 January 2024, 10 months ago

Problem/Motivation

In twig drupal_entity function works incorrect when the source content is unpublished but the requested translation is published.

Steps to reproduce

1. Install drupal, twig_tweak and content translation module
2. Add second language. Let's say it will be 'en-us' and the main language is 'en'.
3. Make the article content type translatable and make the content published/unpublished status translatable too.
4. Create new article. Let's say it will have 1 ID. Make it unpublished.
5. Translate the article into 'en-us' and publish it.
6. Put into page.html.twig the next line: {{ drupal_entity('node', 1, 'teaser') }}
7. Clear caches.
8. Open the website for 'en' version for anonymous user and you will not see the article. That's correct, since it's unpublished.
9. Open the website for 'en-us' version for anonymous user and you will not see the article too. That's wrong, since it's published.

Proposed resolution

I suppose Drupal\twig_tweak\View\EntityViewBuilder::build checks the access for the source content even though you try to render translated content.

As I understand we need to change Drupal\twig_tweak\View\EntityViewBuilder::build to check access for translated entity.

Remaining tasks

1. Test drupal_entity with suggested solution
2. Find similar issues for other functions
3. Fix similar issues

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine lobodacyril

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024