You are here

function _ack_menu_tree_data in Access Control Kit 7

Helper function for ack_menu_tree_data() to build a realm menu tree.

1 call to _ack_menu_tree_data()
ack_menu_tree_data in ack_menu/ack_menu.pages.inc
Sorts and returns a realm's links as a menu tree.

File

ack_menu/ack_menu.pages.inc, line 232
Page callbacks for managing menu links in assigned realms.

Code

function _ack_menu_tree_data(&$links, $plid = 0) {
  $tree = array();
  while ($item = array_pop($links)) {

    // _menu_tree_check_access() expects a value for 'in_active_trail', which
    // we'll just set to FALSE here because ack_menu is not used when building
    // the active trail and breadcrumb.
    $item['in_active_trail'] = FALSE;

    // Add the current link to the tree.
    $tree[$item['mlid']] = array(
      'link' => $item,
      'below' => array(),
    );

    // If the next link is a child of the current link, start a subtree.
    $next = end($links);
    if ($next && $next['plid'] == $item['mlid']) {
      $subtree = _ack_menu_tree_data($links, $item['mlid']);
      if (ack_menu_link_access($item)) {
        $tree[$item['mlid']]['below'] = $subtree;
      }
      $next = end($links);
    }

    // If this is a subtree ($plid > 0) and the next link is not in the subtree,
    // then we need to exit the loop and return.
    if (!$next || $plid && $next['plid'] != $plid) {
      break;
    }
  }
  return $tree;
}