You are here

function _admin_menu_get_children in Administration menu 5

Same name and namespace in other branches
  1. 5.3 admin_menu.inc \_admin_menu_get_children()
  2. 5.2 admin_menu.inc \_admin_menu_get_children()
1 call to _admin_menu_get_children()
admin_menu_get_menu in ./admin_menu.inc
Retrieves, sclices and returns the menu tree below /admin.

File

./admin_menu.inc, line 44

Code

function _admin_menu_get_children(&$admin_items, &$item) {
  global $_menu;
  if (isset($item['children'])) {
    foreach ($item['children'] as $child) {

      // check access permissions
      if (!variable_get('admin_menu_show_all', 0)) {
        $item_is_accessible = !isset($_menu['items'][$child]['access']) || isset($_menu['items'][$child]['access']) && $_menu['items'][$child]['access'];
      }
      else {
        $item_is_accessible = true;
      }

      // check type
      $item_is_visible = $_menu['items'][$child]['type'] & (MENU_VISIBLE_IN_TREE | MENU_IS_LOCAL_TASK);

      // create the child item if it is accessible and visible
      // Additional if condition to hide items linking to parent:
      //   && !($_menu['items'][$child]['type'] & MENU_LINKS_TO_PARENT)
      if ($item_is_accessible && $item_is_visible) {
        $admin_items[$child] = $_menu['items'][$child];

        // recurse to child menu items
        if (isset($_menu['items'][$child]['children'])) {
          _admin_menu_get_children($admin_items, $admin_items[$child]);
        }

        // remove this child item if it is visible in navigation
        unset($_menu['visible'][$child]);
      }
      else {

        // remove child menu item from parent's children list
        $parent_id = $_menu['items'][$child]['pid'];
        if (isset($_menu['items'][$parent_id]['children']) && is_array($_menu['items'][$parent_id]['children'])) {
          $child_key = array_search($child, $_menu['items'][$parent_id]['children']);
          if ($child_key !== false) {
            unset($admin_items[$parent_id]['children'][$child_key]);
          }
        }
      }
    }

    // sort remaining items
    usort($item['children'], '_menu_sort');
  }
}