| 6 menu.inc | menu_tree_output($tree) |
| 7 menu.inc | menu_tree_output($tree) |
| 8 menu.inc | menu_tree_output($tree) |
Returns a rendered menu tree.
Parameters
$tree: A data structure representing the tree as returned from menu_tree_data.
Return value
The rendered HTML of that data structure.
Related topics
3 calls to menu_tree_output()
File
- includes/
menu.inc, line 739 - API for the Drupal menu system.
Code
function menu_tree_output($tree) {
$output = '';
$items = array();
// Pull out just the menu items we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $data) {
if (!$data['link']['hidden']) {
$items[] = $data;
}
}
$num_items = count($items);
foreach ($items as $i => $data) {
$extra_class = array();
if ($i == 0) {
$extra_class[] = 'first';
}
if ($i == $num_items - 1) {
$extra_class[] = 'last';
}
$extra_class = implode(' ', $extra_class);
$link = theme('menu_item_link', $data['link']);
if ($data['below']) {
$output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
}
else {
$output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
}
}
return $output ? theme('menu_tree', $output) : '';
}
Login or register to post comments
Comments
fix for drop down menu on the option enable/disable expanded
<?php
function menu_tree_output($tree) {
$output = '';
$items = array();
// Pull out just the menu items we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $data) {
if (!$data['link']['hidden']) {
$items[] = $data;
}
}
$num_items = count($items);
foreach ($items as $i => $data) {
$extra_class = array();
if ($i == 0) {
$extra_class[] = 'first';
}
if ($i == $num_items - 1) {
$extra_class[] = 'last';
}
$extra_class = implode(' ', $extra_class);
$link = theme('menu_item_link', $data['link']);
// fix for disabled/enabled expanded menu option. it won't show drop down menu when the menu is active
if ($data['link']['expanded']) {
$output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
}
else {
$output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
}
}
return $output ? theme('menu_tree', $output) : '';
}
?>
Duplication
This would better:
// fix for disabled/enabled expanded menu option. it won't show drop down menu when the menu is active$below = $data['link']['expanded'] ? menu_tree_output($data['below']) : '';
$output .= theme('menu_item', $link, $data['link']['has_children'], $below, $data['link']['in_active_trail'], $extra_class);
drupal 6
this has totally worked for us 'til now. Somehow i created a menu item and placed it as a parent. (i was testing the parent item) then i deleted it. now we have this error:
warning: Invalid argument supplied for foreach() in /var/www/drupal/includes/menu.inc on line 734.
any idea what is the issue?
from php website:
"The foreach construct simply gives an easy way to iterate over arrays. foreach works only on arrays (and objects), and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. "
it was working before...
we have the same code as
we have the same code as well...i dropped it about a year ago:
function menu_tree_output($tree) {
$output = '';
$items = array();
// Pull out just the menu items we are going to render so that we
// get an accurate count for the first/last classes.
foreach ($tree as $data) {
if (!$data['link']['hidden']) {
$items[] = $data;
}
}
$num_items = count($items);
foreach ($items as $i => $data) {
$extra_class = NULL;
if ($i == 0) {
$extra_class = 'first';
}
if ($i == $num_items - 1) {
$extra_class = 'last';
}
$link = theme('menu_item_link', $data['link']);
if ($data['below']) {
$output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
}
else {
$output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
}
}
return $output ? theme('menu_tree', $output) : '';
}