- 🇦🇹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(); }