diff --git a/web/modules/contrib/book/src/BookManager.php b/web/modules/contrib/book/src/BookManager.php index 56e51cf..deca0e9 100644 --- a/web/modules/contrib/book/src/BookManager.php +++ b/web/modules/contrib/book/src/BookManager.php @@ -638,6 +638,13 @@ protected function buildItems(array $tree) { $element['in_active_trail'] = TRUE; } + // Set a helper variable to indicate whether the link belongs to + // the current page. + $element['is_active'] = FALSE; + if ($data['link']['is_active']) { + $element['is_active'] = TRUE; + } + // Allow book-specific theme overrides. $element['attributes'] = new Attribute(); $element['title'] = $data['link']['title']; @@ -1113,7 +1120,14 @@ protected function buildBookOutlineData(array $links, array $parents = [], $dept */ protected function buildBookOutlineRecursive(&$links, $parents, $depth) { $tree = []; + $node = \Drupal::routeMatch()->getParameter('node'); + // The instanceof check doesn't filter out NULLs. + if ($node != NULL && !($node instanceof NodeInterface)) { + $node = $this->entityTypeManager->getStorage('node')->load($node); + } while ($item = array_pop($links)) { + // Check if item belongs to the current page. + $item['is_active'] = ($node && $node->id() == $item['nid']) ? TRUE : FALSE; // We need to determine if we're on the path to root so we can later build // the correct active trail. $item['in_active_trail'] = in_array($item['nid'], $parents); diff --git a/web/modules/contrib/book/src/Plugin/Block/BookNavigationBlock.php b/web/modules/contrib/book/src/Plugin/Block/BookNavigationBlock.php index 578ea36..9fe5929 100644 --- a/web/modules/contrib/book/src/Plugin/Block/BookNavigationBlock.php +++ b/web/modules/contrib/book/src/Plugin/Block/BookNavigationBlock.php @@ -142,6 +142,7 @@ public function build() { // Since we know we will only display a link to the top node, there // is no reason to run an additional menu tree query for each book. $book['in_active_trail'] = FALSE; + $book['is_active'] = FALSE; // Check whether user can access the book link. $book_node = $this->nodeStorage->load($book['nid']); $book['access'] = $book_node->access('view'); diff --git a/web/modules/contrib/book/templates/book-tree.html.twig b/web/modules/contrib/book/templates/book-tree.html.twig index 3d3069c..39b88b2 100644 --- a/web/modules/contrib/book/templates/book-tree.html.twig +++ b/web/modules/contrib/book/templates/book-tree.html.twig @@ -16,6 +16,7 @@ * - is_collapsed: TRUE if the link has children within the current book tree * that are not currently visible. * - in_active_trail: TRUE if the link is in the active trail. + * - is_active: TRUE if the link is for the current page. * * @ingroup themeable */