Taxonomy term list view does not show all published nodes on a multilingual site

Created on 11 June 2019, over 5 years ago
Updated 20 March 2024, 8 months ago

Postpone on 🐛 "Has taxonomy term" contextual filter does not take the language value into account Needs work . See #6.

Multilingual site (2 languages - English/ French).

There is a content type "Article" which uses a field of type Entity reference to a taxonomy "Category". Both the content type and the taxonomy are translated. All taxonomy terms in "Category" are translated and published in both both languages. Taxonomy "Category" contains a term "News" (tid = 1).

Field "published" in content type "Article" is translated. There are 10 published articles (nodes) with taxonomy term "News" in English (article1, ..., article10). Of those 5 are translated in French (article1, ..., article5). Four of the translated articles are published in French (article1, ..., article4), one - article5 - is NOT published.

The standard Taxonomy term view - /taxonomy/term/% exhibits two distinct behaviours for the term "News" depending on the last saved version of article5:

1. If we save the French (unpublished) version of article5 last then we get UNEXPECTED (wrong in our opinion) behaviour
/en/taxonomy/term/1 lists article1, ..., article4, article6, ..., article10 - (article5 is MISSING) regardless of the fact that the English version of article5 is PUBLISHED. This is the wrong behaviour.
/fr/taxonomy/term/1 lists article1, ..., article4 which is the correct behaviour.

2. If we save the English (published) version of article5 last then we get the EXPECTED behaviour:
/en/taxonomy/term/1 lists article1, ..., article10 - (article5 is present) which is the correct behaviour.
/fr/taxonomy/term/1 lists article1, ..., article4 which is the correct behaviour.

The problem was traced to taxonomy_index table. On node save of the unpublished (French) version, records related to the published (English) version are removed.

Problem occurs on: 8.6.5, 8.7.2

🐛 Bug report
Status

Postponed

Version

11.0 🔥

Component
Taxonomy 

Last updated 4 days ago

  • Maintained by
  • 🇺🇸United States @xjm
  • 🇬🇧United Kingdom @catch
Created by

🇧🇬Bulgaria ymarkov_str

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.

  • 🇦🇹Austria d.steindl Vienna

    Hi, I encountered this problem, so I had to create a workaround for this issue.

    We are using content moderation on a multilingual site with an "archived" state (DefaultRevision: true, Status: false) --> this means the "Archived" state creates a new unpublished DefaultRevision of a node. The taxonomy module deletes the entries of the taxonomy_index after archiving a french translation of a node, even if there are 4 other translations still published.

    I implemented a workaround which performs the status check in taxonomy_build_node_index for each translation instead of the saved node instance.
    Important note: this patch sets the "status" column of the taxonomy_index table to 1 (hardcoded), since only published translations get added anyways --> On a multilingual site it's necessary to filter by content language & the node's published field in order to get only published nodes!

    Due to lack of time, I haven't been able to create a patch like recommended on drupal.org ( https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa... ). I simply did a git init in my core directory & git diff to a file from my local project (Drupal 9.5.9).

    Anyways, I'll share it here in case anyone needs the patch!

  • 🇮🇳India nishat ahmad

    I changed the patch according to D10 and have tested it, but for Draft mode, it's not working.

    diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
    index 5f011c6..0a52f59 100644
    --- a/core/modules/taxonomy/taxonomy.module
    +++ b/core/modules/taxonomy/taxonomy.module
    @@ -179,10 +179,9 @@ function taxonomy_build_node_index($node) {
         return;
       }
     
    -  $status = $node->isPublished();
    +  //$status = $node->isPublished();
       $sticky = (int) $node->isSticky();
    -  // We only maintain the taxonomy index for published nodes.
    -  if ($status && $node->isDefaultRevision()) {
    +  if ($node->isDefaultRevision()) {
         // Collect a unique list of all the term IDs from all node fields.
         $tid_all = [];
         $entity_reference_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
    @@ -192,11 +191,19 @@ function taxonomy_build_node_index($node) {
           $is_entity_reference_class = ($class === $entity_reference_class) || is_subclass_of($class, $entity_reference_class);
           if ($is_entity_reference_class && $field->getSetting('target_type') == 'taxonomy_term') {
             foreach ($node->getTranslationLanguages() as $language) {
    -          foreach ($node->getTranslation($language->getId())->$field_name as $item) {
    -            if (!$item->isEmpty()) {
    -              $tid_all[$item->target_id] = $item->target_id;
    +          // foreach ($node->getTranslation($language->getId())->$field_name as $item) {
    +          //   if (!$item->isEmpty()) {
    +          //     $tid_all[$item->target_id] = $item->target_id;
    +          /** @var \Drupal\node\NodeInterface $translation */
    +            $translation = $node->getTranslation($language->getId());
    +            // only maintain the taxonomy_index table for published node translations
    +            if($translation->isPublished()) {
    +              foreach($translation->$field_name as $item) {
    +                if(!$item->isEmpty()) {
    +                  $tid_all[$item->target_id] = $item->target_id;
    +                }
    +              }
                 }
    -          }
             }
           }
         }
    @@ -204,8 +211,13 @@ function taxonomy_build_node_index($node) {
         if (!empty($tid_all)) {
           $connection = \Drupal::database();
           foreach ($tid_all as $tid) {
    +        // TODO: the status column makes no sense in the taxonomy_index table,
    +        //   since only published node translations get indexed. That means, that
    +        //   all indexed nids are published in at least one translation language.
    +        //   --> hardcode the 'status' column to 1
             $connection->merge('taxonomy_index')
    -          ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
    +          //->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
    +          ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => 1])
               ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
               ->execute();
           }
    
    
  • 🇮🇳India nishat ahmad

    @d.steindl if you have time do it dynamic.

Production build 0.71.5 2024