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:

  1. 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".
  2. 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

CommentFileSizeAuthor
#2 3353243-2.patch1.34 KBhchonov

Comments

hchonov created an issue. See original summary.

hchonov’s picture

The 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.

hchonov’s picture

Issue summary: View changes
hchonov’s picture

Issue summary: View changes
hchonov’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: 3353243-2.patch, failed testing. View results

piotr pakulski’s picture

Thank you @hchonov looks like the patch is solving my problem. I'm curious if 2951294 is working on solving the problem with failing tests ?

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.