function theme_nice_menus_tree in Nice Menus 6.2
Same name and namespace in other branches
- 7.3 nice_menus.module \theme_nice_menus_tree()
- 7.2 nice_menus.module \theme_nice_menus_tree()
Builds the final Nice menu.
Parameters
string $menu_name: The top-level menu name that contains the menu to use (e.g. navigation or primary-links) for Drupal menus. For custom $menus this is just the name for menu display.
int $mlid: The menu ID from which to start building the items, i.e. the parent of the displayed menu.
int $depth: The number of children levels to display. Use -1 to display all children and use 0 to display no children.
array $menu: Optional. A custom menu array to use for theming -- it should have the same structure as that returned by menu_tree_all_data().
Return value
string An HTML string of properly nested Nice menu lists.
1 theme call to theme_nice_menus_tree()
- theme_nice_menus in ./
nice_menus.module - Theme function to allow any menu tree to be themed as a Nice menu.
File
- ./
nice_menus.module, line 302 - Module to enable CSS dropdown and flyout menus.
Code
function theme_nice_menus_tree($menu_name, $mlid = NULL, $depth = -1, $menu = NULL) {
// Load the full menu array.
$menu = isset($menu) ? $menu : menu_tree_all_data($menu_name);
if (isset($menu)) {
$page_menu = menu_tree_page_data($menu_name);
$trail = nice_menus_build_page_trail($page_menu);
unset($page_menu);
}
// Assume depth == 0 by default, overriden if mlid is specified.
// (http://drupal.org/node/1101722).
$parent_depth = 0;
// Allow i18n module to translate strings where available.
if (module_exists('i18nmenu')) {
i18nmenu_localize_tree($menu);
}
// For custom $menus and menus built all the way from the top-level we
// don't need to "create" the specific sub-menu and we need to get the title
// from the $menu_name since there is no "parent item" array.
// Create the specific menu if we have a mlid.
if (!empty($mlid)) {
// Load the parent menu item.
$item = menu_link_load($mlid);
$title = check_plain($item['title']);
// The depth for our parent item.
$parent_depth = $item['depth'];
// Narrow down the full menu to the specific sub-tree we need.
for ($p = 1; $p < 10; $p++) {
if ($sub_mlid = $item["p{$p}"]) {
$subitem = menu_link_load($sub_mlid);
// Menu sets these ghetto-ass keys in _menu_tree_check_access().
$menu = $menu[50000 + $subitem['weight'] . ' ' . $subitem['title'] . ' ' . $subitem['mlid']]['below'];
}
}
}
else {
// Get the title from the DB since we don't have it in the $menu.
$result = db_result(db_query("SELECT title FROM {menu_custom} WHERE menu_name = '%s'", $menu_name));
$title = check_plain($result);
}
$output['content'] = '';
$output['subject'] = $title;
if ($menu) {
// Set the total menu depth counting from this parent if we need it.
$depth = $depth > 0 ? $parent_depth + $depth : $depth;
$output['content'] .= theme('nice_menus_build', $menu, $depth, $trail);
}
return $output;
}