Chris@0: requestStack = $request_stack; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function getLabel() { Chris@0: return t("Book navigation"); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getContext() { Chris@0: // Find the current book's ID. Chris@0: $current_bid = 0; Chris@0: if ($node = $this->requestStack->getCurrentRequest()->get('node')) { Chris@0: $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid']; Chris@0: } Chris@0: Chris@0: // If we're not looking at a book node, then we're not navigating a book. Chris@0: if ($current_bid === 0) { Chris@0: return 'book.none'; Chris@0: } Chris@0: Chris@0: // If we're looking at a book node, get the trail for that node. Chris@0: $active_trail = $this->container->get('book.manager') Chris@0: ->getActiveTrailIds($node->book['bid'], $node->book); Chris@0: return implode('|', $active_trail); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getCacheableMetadata() { Chris@0: // The book active trail depends on the node and data attached to it. Chris@0: // That information is however not stored as part of the node. Chris@0: $cacheable_metadata = new CacheableMetadata(); Chris@0: if ($node = $this->requestStack->getCurrentRequest()->get('node')) { Chris@0: // If the node is part of a book then we can use the cache tag for that Chris@0: // book. If not, then it can't be optimized away. Chris@0: if (!empty($node->book['bid'])) { Chris@0: $cacheable_metadata->addCacheTags(['bid:' . $node->book['bid']]); Chris@0: } Chris@0: else { Chris@0: $cacheable_metadata->setCacheMaxAge(0); Chris@0: } Chris@0: } Chris@0: return $cacheable_metadata; Chris@0: } Chris@0: Chris@0: }