Problem/Motivation
If we consider a node having English as its source translation and a German translation that is unpublished then when viewing the node in German will result in access being denied. If we would visit the node on the path of the French site though the English translation will be loaded. This is a known discrepancy and a consensus has to be made in #2978048: Unpublished translations should fallback to the original language.
The issue here deals with the case of an entity reference that has an unpublished translation. Up until #2543258: Entity references of untranslatable fields are not displayed in the correct translation Drupal core used to perform the access check on entity translation and thus filter out unpublished entity translations, but with that issue it was changed to go for a fallback translation. I think that back then we did not realize that the reported issue could be solved without adding a translation fallback for referenced entities and we simply wanted to go for the official API for retrieving entity translation from the entity repository, but did not really fully consider the implications of that API.
Depending on the POV it might be right or wrong to fall back to a translation of an entity reference different than the requested one. There are two main branches that we have to differentiate:
- The referenced entity does not have a translation for the requested language.
- The referenced entity has a translation for the requested language, but the current user does not have access to it - e.g. the translation is unpublished.
Steps to reproduce
Proposed resolution
If an entity reference does not have a translation for the requested language then use a fallback. This solves the case when the entity is a carrier for further nested content that is actually translated.
If an entity reference has a translation for the requested language, but the current user does not have an access to it then filter it out - meaning respect the active unpublishing of an entity translation.
Since different sites / editors might have different needs here this probably has to be configurable and there should be ways for a global site configuration and for per-case configuration controllable by the editors:
- Add a global site setting controlling whether a translation fallback is allowed in case a missing access for a translation e.g. "Show mixed translation content".
- Add another property on entity reference fields allowing the editors to further specify whether the target entity can be rendered using fallback translations.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3353243-2.patch | 1.34 KB | hchonov |
Comments
Comment #2
hchonovThe following patch implements a simple approach where a translation fallback through the entity repository will be used only if the referenced entity does not yet have a translation for the requested language. Otherwise, it will behave just like the main entity - the access check will be performed on the target translation and if not granted the target entity will not be displayed.
Comment #3
hchonovComment #4
hchonovComment #5
hchonovComment #7
piotr pakulskiThank you @hchonov looks like the patch is solving my problem. I'm curious if 2951294 is working on solving the problem with failing tests ?