public BookNavigationCacheContext::getContext()
Returns the string representation of the cache context.
A cache context service's name is used as a token (placeholder) cache key, and is then replaced with the string returned by this method.
Return value
string The string representation of the cache context.
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\Cache
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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 ); } |
Please login to continue.