function BookNavigationCacheContext::getContext
Same name in other branches
- 9 core/modules/book/src/Cache/BookNavigationCacheContext.php \Drupal\book\Cache\BookNavigationCacheContext::getContext()
- 10 core/modules/book/src/Cache/BookNavigationCacheContext.php \Drupal\book\Cache\BookNavigationCacheContext::getContext()
- 11.x core/modules/book/src/Cache/BookNavigationCacheContext.php \Drupal\book\Cache\BookNavigationCacheContext::getContext()
Overrides CacheContextInterface::getContext
File
-
core/
modules/ book/ src/ Cache/ BookNavigationCacheContext.php, line 54
Class
- BookNavigationCacheContext
- Defines the book navigation cache context service.
Namespace
Drupal\book\CacheCode
public function getContext() {
// Find the current book's ID.
$current_bid = 0;
if ($node = $this->requestStack
->getCurrentRequest()
->get('node')) {
$current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
}
// If we're not looking at a book node, then we're not navigating a book.
if ($current_bid === 0) {
return 'book.none';
}
// If we're looking at a book node, get the trail for that node.
$active_trail = $this->container
->get('book.manager')
->getActiveTrailIds($node->book['bid'], $node->book);
return implode('|', $active_trail);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.