I want to use Drupal Nice Menus to display certain books, or sub books at any level, but can't see how the theme_nice_menus function will do that.
I am looking at the code samples below for some inspiration:
The first example works an all the books, but I need to pass on selected books, or even a sub book.
The second example works on a single book, but doesn't use nice menu? Can the output of menu_tree_all_data
or menu_tree_output
be passed to the theme_nice_menus
function?
The third one which is from bookoblock module on github displays how to get an individual book, but not a sub book from its children, and doesn't use nice menus.
I am trying to create something of these examples. Generating a menu from a sub book rather than a top level book is one thing I would want to do.
<?php
$master_menu = '';
$books = book_get_books();
foreach($books as $book_nid=>$book) {
$menu = theme('nice_menus', array('id' => $book['mlid'], 'direction' => 'right', 'depth' => -1, 'menu_name' => $book['menu_name'], 'menu' => NULL));
$master_menu .= $menu['content'];
}
print $master_menu;
?>
<?php
$book_top_page= 49;
$tree = menu_tree_all_data(book_menu_name($book_top_page));
print drupal_render(menu_tree_output($tree));
?>
<?php
function bookoblock_block_view() {
if ($book = bookoblock_is_book_node()) {
// menu_build_tree() doesn't accept zero for depth, so we convert that to
// NULL and add 1 if it's not 0 to account for the first (skipped) level.
$max_depth = variable_get('bookoblock_depth', NULL);
$max_depth = ($max_depth == 0) ? NULL : ($max_depth + 1);
// Vars and params for the menu_build_tree() function.
$path = 'node/' . $book['bid'];
$parent = menu_link_get_preferred($path, book_menu_name($book['bid']));
$parameters = array(
'only_active_trail' => FALSE,
'min_depth' => $parent['depth'] + 1,
'max_depth' => $max_depth,
);
// Build the tree and block title.
$children = menu_build_tree($parent['menu_name'], $parameters);
$book_name = (book_toc($book['bid'], 1));
// Build and return the $block array.
$block['subject'] = l($book_name[$book['p1']], 'node/' . $book['bid']);
$block['content'] = menu_tree_output($children);
return $block;
}
// If the current node isn't part of a book, just return nothing.
return NULL;
}
?>