0

Using Views I've created a block which show the immediate children of the current parent book page. What I really want is a block that shows the total child hierarchy of the current parent book page. My intention is to place these blocks on just certain pages which have no content but are there for content grouping. I'm on Drupal 9 if it matters.

This is the screenshot of the fields in the block view.

screenshot

This is the screenshot showing the first advanced settings of the view.

screenshot

This is the screenshot of the block rendered on one of my book pages.

screenshot

Each of those headings have a hierarchy beneath them. I want to see the expanded tree rather than just the immediate child pages.

Is there a way to modify the view to show all children pages?

2
  • What the screenshot shows isn't how the view looks, but part of the advanced settings of that view. Knowing more about its settings would probably help to provide a better answer. It would also help if the question described exactly what you don't understand in achieving the described task.
    – avpaderno
    Commented Mar 12, 2021 at 16:00
  • @kiamlaluno I've added more detail to the original post.
    – Chanel
    Commented Mar 12, 2021 at 20:28

1 Answer 1

1

It's been more than a year, but I'll drop my solution:

You can tweak Drupal's book navigation block (that's displayed under nodes) usinghook_preprocess_book_navigation to add full tree.

use Drupal\book\BookManager;

function MYTHEME_preprocess_book_navigation(&$variables) {
  
  $book_link = $variables['book_link'];
  $variables['tree'] = ''; //Remove existing tree

  $book_manager = \Drupal::service('book.manager');
  if ($book_link['nid']) {
    $book_tree = $book_manager->bookSubtreeData($book_link); //Get the full tree for the current node
    $book_tree = reset($book_tree)['below']; //Remove current node from tree. 
    $variables['tree'] = $book_manager->bookTreeOutput($book_tree); // re-create the tree
  }
}

You can tweak the layout of the items with book-tree.html.twig and the main block with book-navigation.html.twig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.