menu_tree_output

Versions
6 – 7
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

▾ 4 functions call menu_tree_output()

book_block in modules/book/book.module
Implementation of hook_block().
book_children in modules/book/book.module
Format the menu links for the child pages of the current page.
menu_tree in includes/menu.inc
Render a menu tree based on the current path.
menu_tree_output in includes/menu.inc
Returns a rendered menu tree.

Code

includes/menu.inc, line 736

<?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 = 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) : '';
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.