From 3b24280d541046f7f1ae1024359d774a3bdc2254 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Mon, 16 Mar 2026 14:17:09 +1100 Subject: [PATCH 1/3] [SD-1497] Added cachebale dependencies for publication navigation computed fields. --- modules/tide_publication/src/Navigation/Children.php | 8 ++++++-- modules/tide_publication/src/Navigation/Next.php | 7 ++++++- modules/tide_publication/src/Navigation/Previous.php | 9 +++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/modules/tide_publication/src/Navigation/Children.php b/modules/tide_publication/src/Navigation/Children.php index e90fa9ac2..744a8f236 100644 --- a/modules/tide_publication/src/Navigation/Children.php +++ b/modules/tide_publication/src/Navigation/Children.php @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheableMetadata; /** - * Class Root. + * Class Children. */ class Children extends Base { @@ -44,6 +44,10 @@ protected function computeValue() { $this->list[] = $this->createItem($weight, ['target_id' => $child_id]); } + + // Add the collected cacheable metadata to the parent entity. + // This ensures that if any child changes, the cache for this field is invalidated. + $entity->addCacheableDependency($cache); } -} +} \ No newline at end of file diff --git a/modules/tide_publication/src/Navigation/Next.php b/modules/tide_publication/src/Navigation/Next.php index 75ff62b9d..981d12c8b 100644 --- a/modules/tide_publication/src/Navigation/Next.php +++ b/modules/tide_publication/src/Navigation/Next.php @@ -31,11 +31,16 @@ protected function computeValue() { $next = $delta + 1; if (isset($hierarchy[$next])) { $this->list[] = $this->createItem(0, ['target_id' => $hierarchy[$next]['entity_id']]); - return; + // Break the loop and proceed to add cache metadata. + break; } } } } + + // Add the collected cacheable metadata to the parent entity. + // This ensures the field invalidates if the root or any hierarchy node changes. + $entity->addCacheableDependency($cache); } } diff --git a/modules/tide_publication/src/Navigation/Previous.php b/modules/tide_publication/src/Navigation/Previous.php index 59fb55c1f..4df8f4e83 100644 --- a/modules/tide_publication/src/Navigation/Previous.php +++ b/modules/tide_publication/src/Navigation/Previous.php @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheableMetadata; /** - * Class Next. + * Class Previous. */ class Previous extends Base { @@ -31,11 +31,16 @@ protected function computeValue() { $prev = $delta - 1; if (isset($hierarchy[$prev])) { $this->list[] = $this->createItem(0, ['target_id' => $hierarchy[$prev]['entity_id']]); - return; + // Use break instead of return so we reach the cache dependency call below. + break; } } } } + + // Attach the collected cache metadata to the entity. + // This tells Drupal that this field depends on all nodes in the hierarchy. + $entity->addCacheableDependency($cache); } } From d2deb9256858ddc31c68e26c5bb559df925c6841 Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Mon, 16 Mar 2026 14:19:10 +1100 Subject: [PATCH 2/3] lint fix. --- modules/tide_publication/src/Navigation/Children.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/tide_publication/src/Navigation/Children.php b/modules/tide_publication/src/Navigation/Children.php index 744a8f236..b76d2fcc0 100644 --- a/modules/tide_publication/src/Navigation/Children.php +++ b/modules/tide_publication/src/Navigation/Children.php @@ -50,4 +50,4 @@ protected function computeValue() { $entity->addCacheableDependency($cache); } -} \ No newline at end of file +} From acedb0c7c57e95402b48e680decf6000446e9a1d Mon Sep 17 00:00:00 2001 From: Md Nadim Hossain Date: Mon, 16 Mar 2026 14:46:51 +1100 Subject: [PATCH 3/3] lint fix. --- modules/tide_publication/src/Navigation/Children.php | 4 ++-- modules/tide_publication/src/Navigation/Next.php | 2 +- modules/tide_publication/src/Navigation/Previous.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/tide_publication/src/Navigation/Children.php b/modules/tide_publication/src/Navigation/Children.php index b76d2fcc0..705ef5330 100644 --- a/modules/tide_publication/src/Navigation/Children.php +++ b/modules/tide_publication/src/Navigation/Children.php @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheableMetadata; /** - * Class Children. + * Class Children for navigation. */ class Children extends Base { @@ -46,7 +46,7 @@ protected function computeValue() { } // Add the collected cacheable metadata to the parent entity. - // This ensures that if any child changes, the cache for this field is invalidated. + // If any child changes, the cache for this field is invalidated. $entity->addCacheableDependency($cache); } diff --git a/modules/tide_publication/src/Navigation/Next.php b/modules/tide_publication/src/Navigation/Next.php index 981d12c8b..e2d126222 100644 --- a/modules/tide_publication/src/Navigation/Next.php +++ b/modules/tide_publication/src/Navigation/Next.php @@ -39,7 +39,7 @@ protected function computeValue() { } // Add the collected cacheable metadata to the parent entity. - // This ensures the field invalidates if the root or any hierarchy node changes. + // Make sure field invalidates if the root or any hierarchy node changes. $entity->addCacheableDependency($cache); } diff --git a/modules/tide_publication/src/Navigation/Previous.php b/modules/tide_publication/src/Navigation/Previous.php index 4df8f4e83..2d4b677a9 100644 --- a/modules/tide_publication/src/Navigation/Previous.php +++ b/modules/tide_publication/src/Navigation/Previous.php @@ -5,7 +5,7 @@ use Drupal\Core\Cache\CacheableMetadata; /** - * Class Previous. + * Class Previous for navigation. */ class Previous extends Base { @@ -39,7 +39,7 @@ protected function computeValue() { } // Attach the collected cache metadata to the entity. - // This tells Drupal that this field depends on all nodes in the hierarchy. + // Tells Drupal field depends on all nodes in the hierarchy. $entity->addCacheableDependency($cache); }