function simplemenu_get_menu in SimpleMenu 6
Same name and namespace in other branches
- 5 simplemenu.module \simplemenu_get_menu()
- 6.2 simplemenu.module \simplemenu_get_menu()
- 7 simplemenu.module \simplemenu_get_menu()
Render an HTML list of links for a given menu.
1 call to simplemenu_get_menu()
- _simplemenu_add_menu in ./
simplemenu.module - \brief Add the simplemenu variable with the menu to be displayed.
File
- ./
simplemenu.module, line 335 - Creates a simplemenu.
Code
function simplemenu_get_menu() {
simplemenu_running(TRUE);
// if a user turned off menu module but SimpleMenu was previously set
// reset variable so a menu appears
$all_menus = array(
variable_get('simplemenu_menu', 'navigation:0'),
);
drupal_alter('simplemenu_menus', $all_menus);
if (count($all_menus) > 1) {
// if menu is not enable then we cannot have a count other than 1
$menu_titles = menu_get_menus();
$tree = array();
foreach ($all_menus as $full_name) {
list($menu_name, $mlid) = explode(':', $full_name);
$tree[] = array(
'link' => array(
'simplemenu_multi_menu_root' => TRUE,
'mlid' => $mlid,
'menu_name' => $full_name,
'hidden' => FALSE,
'title' => $menu_titles[$menu_name],
'href' => 'admin/settings/simplemenu',
/// ??? -- we should not have a link here
'in_active_trail' => FALSE,
'has_children' => TRUE,
'localized_options' => array(
'attributes' => array(
'class' => 'simplemenu-top-level',
),
),
),
'below' => simplemenu_menu_tree($full_name),
);
}
}
else {
reset($all_menus);
$tree = simplemenu_menu_tree(current($all_menus));
}
// allow other modules to modify the menu tree
drupal_alter('simplemenu_tree', $tree);
// now generate the output
// by default avoid calling the theme() function
$in_block = !variable_get('simplemenu_call_theme', FALSE);
if (!$in_block) {
// if we are editing a block, then we MUST avoid calling theme().
$in_block = arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'block';
if ($in_block && arg(3)) {
$in_block = arg(3) == 'list';
}
}
if ($in_block) {
// this is a duplicate of the Core function where I replaced
// the theme() calls with the actual function code (& optimized!)
$menu = simplemenu_tree_output($tree, '');
}
else {
// See http://drupal.org/node/816036
// http://drupal.org/node/336119
//
// This function calls theme() and that's bad for anyone
// who uses more than one theme (admin theme(), blocks
// list, etc.) and the theming of the menu items may very
// well break the simplemenu expected <ul>/<li> combinaison.
$menu = menu_tree_output($tree);
}
if (!$menu) {
if (variable_get('simplemenu_hide_when_empty', FALSE)) {
// this is useful for people who have different users with
// different roles and when some do not have enough right
// to see anything, the menu disappears completely
simplemenu_running(FALSE);
return;
}
// some default in case no menu was selected
$menu = '<ul class="menu"><li><a href="' . url('admin/settings/simplemenu') . '">' . t('No menu items found. Try a different menu as the default.') . '</a></li></ul>';
}
// add the id to the UL tag here instead of the JavaScript
// otherwise it could be added to the <div> tag instead...
$pos = strpos($menu, '>');
$menu = str_replace('class="menu', 'class="menu clear-block', substr($menu, 0, $pos)) . ' id="simplemenu"' . substr($menu, $pos);
simplemenu_running(FALSE);
return '<div class="simplemenu-block">' . $menu . '</div>';
}