_menu_build_visible_tree

  1. drupal
    1. 4.7
    2. 5
Versions
4.7 – 5 _menu_build_visible_tree($pid = 0)

Find all visible items in the menu tree, for ease in displaying to user.

Since this is only for display, we only need title, path, and children for each item.

▾ 2 functions call _menu_build_visible_tree()

_menu_build in includes/menu.inc
Build the menu by querying both modules and the database.
_menu_build_visible_tree in includes/menu.inc
Find all visible items in the menu tree, for ease in displaying to user.

Code

includes/menu.inc, line 1155

<?php
function _menu_build_visible_tree($pid = 0) {
  global $_menu;

  if (isset($_menu['items'][$pid])) {
    $parent = $_menu['items'][$pid];

    $children = array();
    if (isset($parent['children'])) {
      usort($parent['children'], '_menu_sort');
      foreach ($parent['children'] as $mid) {
        $children = array_merge($children, _menu_build_visible_tree($mid));
      }
    }
    $visible = ($parent['type'] & MENU_VISIBLE_IN_TREE) ||
      ($parent['type'] & MENU_VISIBLE_IF_HAS_CHILDREN && count($children) > 0);
    $allowed = _menu_item_is_accessible($pid);

    if (($parent['type'] & MENU_IS_ROOT) || ($visible && $allowed)) {
      $_menu['visible'][$pid] = array(
        'title' => $parent['title'],
        'path' => $parent['path'],
        'children' => $children,
        'type' => $parent['type'],
      );
      foreach ($children as $mid) {
        $_menu['visible'][$mid]['pid'] = $pid;
      }
      return array($pid);
    }
    else {
      return $children;
    }
  }

  return array();
}
?>