From 4c60fb7a47412497072e9bfe7d4013c20c6c2d70 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Wed, 7 May 2025 08:41:48 +1000 Subject: [PATCH 1/3] Ensure translation is loaded via getTranslation(). --- modules/quant_cron/quant_cron.module | 6 ++++-- src/Plugin/QueueItem/NodeItem.php | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/modules/quant_cron/quant_cron.module b/modules/quant_cron/quant_cron.module index 0c27e353..2df76bbd 100644 --- a/modules/quant_cron/quant_cron.module +++ b/modules/quant_cron/quant_cron.module @@ -70,7 +70,8 @@ function quant_cron_cron() { if (!empty($filter) && !in_array($langcode, $filter)) { continue; } - Seed::seedNode($entity, $langcode); + $translated_entity = $entity->getTranslation($langcode); + Seed::seedNode($translated_entity, $langcode); \Drupal::logger('quant_cron')->notice("quant_cron sending node: nid: @nid, langcode: @lang", [ @@ -92,7 +93,8 @@ function quant_cron_cron() { $term = Term::load($tid); foreach ($term->getTranslationLanguages() as $langcode => $language) { - Seed::seedTaxonomyTerm($term, $langcode); + $translated_term = $term->getTranslation($langcode); + Seed::seedTaxonomyTerm($translated_term, $langcode); \Drupal::logger('quant_cron')->notice("quant_cron sending term: tid: @tid, langcode: @lang", [ diff --git a/src/Plugin/QueueItem/NodeItem.php b/src/Plugin/QueueItem/NodeItem.php index 3aa580ff..ff188f76 100644 --- a/src/Plugin/QueueItem/NodeItem.php +++ b/src/Plugin/QueueItem/NodeItem.php @@ -60,11 +60,33 @@ public function send() { $entity = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($this->vid); } + if (!$entity) { + \Drupal::logger('quant')->error( + 'Failed to load entity for node ID: @id, revision ID: @vid', + [ + '@id' => $this->id, + '@vid' => $this->vid, + ] + ); + return; + } + foreach ($entity->getTranslationLanguages() as $langcode => $language) { if (!empty($this->filter) && !in_array($langcode, $this->filter)) { continue; } - Seed::seedNode($entity, $langcode); + + \Drupal::logger('quant_seed')->notice( + 'Processing language @langcode for node @id', + [ + '@langcode' => $langcode, + '@id' => $this->id, + ] + ); + + // getTranslation provides more accurate published status. + $translated_entity = $entity->getTranslation($langcode); + Seed::seedNode($translated_entity, $langcode); } } From 09ea2d3569c6a1d398e4affd30c8d5a1dea1ce7e Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Tue, 8 Jul 2025 16:26:46 -0700 Subject: [PATCH 2/3] Move entity translation logic to Seed. --- modules/quant_cron/quant_cron.module | 6 ++---- src/Plugin/QueueItem/NodeItem.php | 6 ++---- src/Seed.php | 7 +++++++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/quant_cron/quant_cron.module b/modules/quant_cron/quant_cron.module index 2df76bbd..0c27e353 100644 --- a/modules/quant_cron/quant_cron.module +++ b/modules/quant_cron/quant_cron.module @@ -70,8 +70,7 @@ function quant_cron_cron() { if (!empty($filter) && !in_array($langcode, $filter)) { continue; } - $translated_entity = $entity->getTranslation($langcode); - Seed::seedNode($translated_entity, $langcode); + Seed::seedNode($entity, $langcode); \Drupal::logger('quant_cron')->notice("quant_cron sending node: nid: @nid, langcode: @lang", [ @@ -93,8 +92,7 @@ function quant_cron_cron() { $term = Term::load($tid); foreach ($term->getTranslationLanguages() as $langcode => $language) { - $translated_term = $term->getTranslation($langcode); - Seed::seedTaxonomyTerm($translated_term, $langcode); + Seed::seedTaxonomyTerm($term, $langcode); \Drupal::logger('quant_cron')->notice("quant_cron sending term: tid: @tid, langcode: @lang", [ diff --git a/src/Plugin/QueueItem/NodeItem.php b/src/Plugin/QueueItem/NodeItem.php index ff188f76..40ad83c9 100644 --- a/src/Plugin/QueueItem/NodeItem.php +++ b/src/Plugin/QueueItem/NodeItem.php @@ -76,7 +76,7 @@ public function send() { continue; } - \Drupal::logger('quant_seed')->notice( + \Drupal::logger('quant')->notice( 'Processing language @langcode for node @id', [ '@langcode' => $langcode, @@ -84,9 +84,7 @@ public function send() { ] ); - // getTranslation provides more accurate published status. - $translated_entity = $entity->getTranslation($langcode); - Seed::seedNode($translated_entity, $langcode); + Seed::seedNode($entity, $langcode); } } diff --git a/src/Seed.php b/src/Seed.php index 9f71efb7..d8e72a7f 100644 --- a/src/Seed.php +++ b/src/Seed.php @@ -212,6 +212,10 @@ public static function unpublishRedirect($redirect) { * Seeds taxonomy term. */ public static function seedTaxonomyTerm($entity, $langcode = NULL) { + + // Use the translation to ensure correct metadata such as published state. + $entity = $entity->getTranslation($langcode); + $tid = $entity->get('tid')->value; $url = Utility::getCanonicalUrl('taxonomy_term', $tid, $langcode); @@ -264,6 +268,9 @@ public static function seedTaxonomyTerm($entity, $langcode = NULL) { */ public static function seedNode(EntityInterface $entity, $langcode = NULL) { + // Use the translation to ensure correct metadata such as published state. + $entity = $entity->getTranslation($langcode); + $nid = $entity->get('nid')->value; $rid = $entity->get('vid')->value; From 154754007076e1b70d102be104cd4b752abfc040 Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Tue, 8 Jul 2025 17:16:21 -0700 Subject: [PATCH 3/3] Update logger context. --- src/Plugin/QueueItem/NodeItem.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin/QueueItem/NodeItem.php b/src/Plugin/QueueItem/NodeItem.php index 40ad83c9..2e9789bb 100644 --- a/src/Plugin/QueueItem/NodeItem.php +++ b/src/Plugin/QueueItem/NodeItem.php @@ -61,7 +61,7 @@ public function send() { } if (!$entity) { - \Drupal::logger('quant')->error( + \Drupal::logger('quant_seed')->error( 'Failed to load entity for node ID: @id, revision ID: @vid', [ '@id' => $this->id, @@ -76,7 +76,7 @@ public function send() { continue; } - \Drupal::logger('quant')->notice( + \Drupal::logger('quant_seed')->notice( 'Processing language @langcode for node @id', [ '@langcode' => $langcode,