Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion modules/tide_publication/src/Navigation/Children.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Drupal\Core\Cache\CacheableMetadata;

/**
* Class Root.
* Class Children for navigation.
*/
class Children extends Base {

Expand Down Expand Up @@ -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.
// If any child changes, the cache for this field is invalidated.
$entity->addCacheableDependency($cache);
}

}
7 changes: 6 additions & 1 deletion modules/tide_publication/src/Navigation/Next.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// Make sure field invalidates if the root or any hierarchy node changes.
$entity->addCacheableDependency($cache);
}

}
9 changes: 7 additions & 2 deletions modules/tide_publication/src/Navigation/Previous.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Drupal\Core\Cache\CacheableMetadata;

/**
* Class Next.
* Class Previous for navigation.
*/
class Previous extends Base {

Expand All @@ -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.
// Tells Drupal field depends on all nodes in the hierarchy.
$entity->addCacheableDependency($cache);
}

}
Loading