My question is about how to show the entire book navigation tree in a block (drupal 8)
Thanks to @oknate we can have a Book Navigation block with the top level book showing, But i need the whole tree. (think table of contents)
All the folowing examples assume you are are the top page of a 3 level deep book.
Also, I have a working module at https://github.com/petergus/alt-book-nav.git
Showing the title (top level) book in the book navigation block is done by replacing the following in book/src/Plugin/Block/BookNavigationBlock.php (with a custom module of course)
// Only show the block if the user has view access for the top-level node.
if ($nid) {
$tree = $this->bookManager->bookTreeAllData($node->book['bid'], $node->book);
// There should only be one element at the top level.
$data = array_shift($tree);
$below = $this->bookManager->bookTreeOutput($data['below']);
if (!empty($below)) {
return $below;
}
}
with
if ($nid) {
$tree = $this->bookManager->bookTreeAllData($node->book['bid'], $node->book);
return $this->bookManager->bookTreeOutput($tree);
}
That only shows the top level and child level though, I want to be able to view the full tree from any page.
I am completely new with drupal 8 and not very handy with PHP so all i could find out was that
$tree = $this->bookManager->bookTreeAllData($node->book['bid'], $node->book);
kint($tree);
returns only the book name and first level and
$tree = $this->bookManager->bookTreeAllData($node->book['bid']);
kint($tree);
(without the $node->book
) returns multiples levels, that is, multiple 'below' arrays.
I have no idea how to go further with pulling that information into the block, does someone?
As mentioned above, I have the module that @oknate suggested at https://github.com/petergus/alt-book-nav.git
Greatly appreciating any help, and hoping this questions serves the community.