Prevent language fallback to happen when a translation is unpublished

Created on 2 December 2020, over 4 years ago
Updated 18 February 2023, about 2 years ago

Problem/Motivation

In this particular example, I'm having translatable nodes with a paragraph field on them. Each paragraph has a "published" flag which itself is translatable. The goal was if I have a translation of the node but don't want to show one of the paragraphs there, I could simply unpublish it and it won't get shown on the translation.

What actually happens is that another language of the same paragraph which itself is published (coming from another translation of the same node) is being shown.

Using the hook_language_fallback_candidates_OPERATION_alter hook I could empty the $candidates, but the default language of the site would still get added in the candidates list and therefore the paragraph would be shown in the site's default language.

Proposed resolution

When I supposedly clear the $candidates array in hook_language_fallback_candidates_OPERATION_alter, the core should check for this case and not add the default language, so we still display this exact entity translation, which in the end won't get displayed because of status = 0.

โœจ Feature request
Status

Needs work

Version

9.5

Component
Entityย  โ†’

Last updated about 3 hours ago

  • Maintained by
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @catch
  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland @berdir
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany @hchonov
Created by

๐Ÿ‡จ๐Ÿ‡ญSwitzerland florianmuellerch Aarau, Switzerland

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request โ†’ as a guide.

    Moving back for tests

    Did not review.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium kristiaanvandeneynde Antwerp, Belgium

    Duplicate of ๐Ÿ› EntityRepository::getTranslationFromContext() function forcibly adds default entity language to fallback candidates Needs review ? This one is older, but the other one is more generic and explains the problem space well. They both relate to candidates being empty from a hook, but this issue tries to get ahead of EntityRepository adding the default back in, whereas the other issue handles it in a backwards compatible way.

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada alberto56

    I have inherited a project which uses this patch, and I'm trying to figure out what this patch does exactly.

    I have created a node in language fr and a translation in language fr-fr.

    The node in fr has a paragraph test, which is published; and the paragraph is translated in fr-fr so that it's not published.

    From reading this patch description, I would expect:

    * That with the patch, the paragraph test does not appear in fr-fr
    * That without the patch, the paragraph test appears in fr-fr even though it is unpublished in fr-fr (put published in fr).

    However, whether or not I apply this patch, the paragraph does not appear in fr-fr.

    In fact I cannot see any difference anywhere on my website whether I apply this patch or not.

    If anyone can advise me on a step by step guide to reproducing a scenario where the site will act differently with and without this patch, when starting from a brand new Drupal site, that would be very appreciated!

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland florianmuellerch Aarau, Switzerland

    @alberto56 I expect this behavior as you wrote only if the paragraphs field itself is not translatable (Paragraph fields officially do not support that). I assume that if itโ€˜s translatable, the two values (fr and fr-fr) are no longer connected.

    Maybe also try with another language like de or en (just more standard that fr-fr). But otherwise your suggestion should sound right (except without the patch, the fr-Version should be shown in fr-fr to be precise, because fr-fr is unpublished which then falls back to fr).

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada alberto56

    @florianmuellerch thanks,

    I have tried to reproduce what you said in the issue description:

    In this particular example, I'm having translatable nodes with a paragraph field on them. Each paragraph has a "published" flag which itself is translatable. The goal was if I have a translation of the node but don't want to show one of the paragraphs there, I could simply unpublish it and it won't get shown on the translation.

    What actually happens is that another language of the same paragraph which itself is published (coming from another translation of the same node) is being shown.

    I have installed a new Drupal 11.1.0 site and then did the following:

    * drush site:install -y
    * composer require drupal/paragraphs
    * create a module mymodule which implements function mymodule_language_fallback_candidates_locale_lookup_alter(array &$candidates, array $context) { $candidates = []; }
    * drush en -y paragraphs language content_translation mymodule
    * /admin/config/regional/language/add
    * Language nane: French
    * Click "Add language"
    * /admin/structure/types/manage/page
    * In Language Settings, select "Enable translation"
    * Save
    * /admin/structure/paragraphs_type/add
    * Label: test paragraph
    * Save and manage fields
    * Create a new field
    * Select "Plain text" and continue
    * Label: "Field inside paragraph"
    * Selct "Text (plain)"
    * Continue
    * Save settings
    * /fr/admin/structure/paragraphs_type/test_paragraph/form-display
    * Put "Published" in the visible section and save
    * /admin/structure/types/manage/page/fields/add-field
    * Select "Paragraphs" and continue
    * Label: Paragraph
    * Check "Test paragraph"
    * Save
    * /admin/config/regional/content-language
    * Check "Paragraphs"
    * Unfold the Paragraphs section
    * Check the "test paragraph" and its sub-fields, "Published" and "Authored on"
    * Save configuration
    * /node/add/page
    * Title: "page in English"
    * In "Field inside paragraph" write "Hello world"
    * save
    * /fr/node/1/translations/add/en/fr
    * Title: "Page in French"
    * In the paragraph, uncheck Published
    * Save (this translation)
    * visit /fr/node/1 in an incognito window
    * confirm you see "Hello world" even though the paragraph is unpublished in the French translation
    * curl -O https://www.drupal.org/files/issues/2022-11-10/3186034_10_respect_empty_... โ†’
    * patch -p1 < 3186034_10_respect_empty_translation_candidates.patch
    * drush cr
    * visit /fr/node/1 in an incognito window
    * based on the issue description, I would expect *not* to see "Hello world", but I see it.

    I will do some more tests but for now I cannot reproduce a scenario where my site acts differently with this patch than without it.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia flutterstack

    I have installed a new Drupal 11.1.0 site and then did the following:

    Before Applying Patch:-

    * drush site:install -y
    * composer require drupal/paragraphs
    * drush en -y paragraphs language content_translation
    * /admin/config/regional/language/add
    * Language name: French
    * Click "Add language"
    * /admin/structure/types/manage/page
    * In Language Settings, select "Enable translation"
    * Save
    * /admin/structure/paragraphs_type/add
    * Label: test paragraph
    * Save and manage fields
    * Create a new field
    * Select "Plain text" and continue
    * Label: "Field inside paragraph"
    * Selct "Text (plain)"
    * Continue
    * Save settings
    * /admin/structure/paragraphs_type/test_paragraph/form-display
    * Put "Published" in the visible section and save
    * /admin/structure/types/manage/page/fields/add-field
    * Select "Paragraphs" and continue
    * Label: Paragraph
    * Check "Test paragraph"
    * Save
    * /admin/config/regional/content-language
    * Check "Paragraphs"
    * Unfold the Paragraphs section
    * Check the "test paragraph" and its sub-fields, "Published" and "Authored on"
    * Save configuration
    * /node/add/page
    * Title: "page in English"
    * In "Field inside paragraph" write "English Hello world"
    * save
    * /fr/node/1/translations/add/en/fr
    * Title: "Page in French"
    * In "Field inside paragraph" write "French Hello world"
    * save
    * In the paragraph, check Published (It is enabled by default)
    * Save (this translation)
    * visit /fr/node/1 in an incognito window
    * confirm you see "French Hello world"
    * now edit french content /fr/node/1/edit
    * In "Field inside paragraph" uncheck Published
    * Save (this translation)
    * visit /fr/node/1 in an incognito window
    * confirm you see "English Hello world"

    Because of language fallback we are seeing "English Hello world"

    Apply the patch :-
    * curl -O https://www.drupal.org/files/issues/2022-11-10/3186034_10_respect_empty_... โ†’
    * patch -p1 < 3186034_10_respect_empty_translation_candidates.patch
    * clear catch $ drush cr
    * visit /fr/node/1 in an incognito window
    even though the paragraph is unpublished in the French translation
    * confirm I see "English Hello world"

    I have tried in drupal 10 and drupal 11 and tried both the patches one after the other both are not preventing language fallback .

Production build 0.71.5 2024