Unpublished paragraphs in translated content incorrectly showing source language content to anonymous users.

Created on 16 November 2016, over 8 years ago
Updated 7 May 2025, 5 days ago

Unpublished paragraphs in translated content incorrectly showing source language content to anonymous users when translated.

Steps to reproduce:

  1. Install Drupal 8.2.2 with standard profile
  2. Enable config_translation, content_translation, local
  3. Install and enable Paragraphs 8.x-1.x-dev
  4. Add additional languages to the site
  5. Set interface (and content detection) methods to URL
  6. Add a new paragraph type with one text Text (formatted) field
  7. Configure the form display for the new paragraph type and set the Published field to be visible and and use the Single On/Off Checkbox formatter
  8. Add this new paragraph type to the Basic page content type
  9. Configure all fields on the Basic page content type and the new paragraph type to be translatable, including the paragraph's published field
  10. Create a new Basic page node in the site's default language and add a paragraph with test content and set its status as Published
  11. Translate this Basic page and change the title and unpublish the paragraph provided by the source content

Test Scenarios:

  • As user 1, view the Basic page node in the source language. You should see the source node title and paragraph content display as expected.
  • As user 1, view the Basic page node in the non-source language. You should see the node title and paragraph content display as expected in the non-source language -- the paragraph not shown because it is unpublished.
  • As anonymous, view the Basic page node in the source language. You should see the node title and paragraph content display as expected.

Failed Test Scenarios:

Expected :

As anonymous, view the Basic page node in the non-source language. You should see the node title and paragraph content display as expected in the non-source language -- the paragraph not shown because it is unpublished.

Actual:

As anonymous, view the Basic page node in the non-source language. You should see the node title display as expected in the non-source language, but the paragraph content displayed is from the source language content.

🐛 Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇺🇸United States gg4

Live updates comments and jobs are added and updated live.
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.

  • florianmuellerch I got the same problem as you, and I think the hook `hook_entity_access` could be the solution:

    /**
     * Implements hook_entity_access().
     */
    function my_custom_paragraphs_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
      if ($entity->getEntityTypeId() == 'paragraph') {
        if ($operation == 'view') {
          // Get the current language.
          $current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
    
          // Check if the paragraph has a translation in the current language.
          if ($entity->hasTranslation($current_language)) {
            // Get the translation.
            $translation = $entity->getTranslation($current_language);
    
            // Check if the translation is not published.
            if (!$translation->isPublished()) {
              return \Drupal\Core\Access\AccessResult::forbidden();
            }
          }
        }
      }
      return \Drupal\Core\Access\AccessResult::neutral();
    }
    
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
Production build 0.71.5 2024