我想使用Drupal Nice Menus来显示任何级别的某些图书或子图书,但无法看到theme_nice_menus函数将如何执行此操作。
我正在查看下面的代码示例,以获得一些灵感:
第一个例子适用于所有书籍,但我需要传递选定的书籍,甚至是子书。
第二个例子适用于一本书,但不使用漂亮的菜单?可以将menu_tree_all_data
或menu_tree_output
的输出传递给theme_nice_menus
函数吗?
来自github上的bookoblock模块的第三个显示如何获取单个书籍,但不显示子书中的子书,并且不使用漂亮的菜单。
我正在尝试创建这些示例。从子书而不是顶级书中生成菜单是我想要做的一件事。
<?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;
}
?>
答案 0 :(得分:0)
我决定使用第一种方法,调整Drupal API book_get_books函数的代码,只选择所需的书籍。
<?php
$master_menu = '';
unset($four_books);
$four_books_list = "91,323,47,149";
$four_books = &drupal_static(__FUNCTION__);
if (!isset($four_books)) {
$four_books = array();
$nids = db_query("SELECT DISTINCT(bid) FROM {book} where bid in (91,323,47,149)")->fetchCol();
if ($nids) {
$query = db_select('book', 'b', array('fetch' => PDO::FETCH_ASSOC));
$query->join('node', 'n', 'b.nid = n.nid');
$query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
$query->addField('n', 'type', 'type');
$query->addField('n', 'title', 'title');
$query->fields('b');
$query->fields('ml');
$query->condition('n.nid', $nids, 'IN');
$query->condition('n.status', 1);
$query->orderBy('ml.weight');
$query->orderBy('ml.link_title');
$query->addTag('node_access');
$result2 = $query->execute();
foreach ($result2 as $link) {
$link['href'] = $link['link_path'];
$link['options'] = unserialize($link['options']);
$four_books[$link['bid']] = $link;
}
}
}
foreach($four_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;
?>