2

If I have some nodes that are of type book, how can I go through them in a php script and tell which is the root? thanks

1
  • 1
    can you elaborate your question? – Ashish Deynap Feb 11 '17 at 6:16
2

You can try to build the menu tree for your book. Book nodes do not have direct parents. The relationship is defined by the menu structure.

This will give you the structure of the book menu.

$book = $node->book;
$tree = menu_tree_all_data(book_menu_name($book['bid']));
2
  • I got this error Error: Call to undefined function book_menu_name() – Diana Feb 13 '17 at 14:59
  • This function is part of the book.module file. It should be available after Drupal bootstrapped. Where exactly are you putting your code? – schlicki Feb 13 '17 at 16:27

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