You are here

function menu_workbench_access_tree in Workbench Access 7

Implements hook_workbench_access_tree().

Get the access tree for a menu item.

Parameters

$info: An array defining the access scheme.

$keys: Boolean value to return only array keys, or all data.

Return value

An array of access_ids or a data array.

File

modules/menu.workbench_access.inc, line 104
Menu integration for Workbench Access.

Code

function menu_workbench_access_tree($info, $keys) {
  $tree = array();
  $items = array();
  if (isset($info['access_id'])) {
    if ($info['access_type_id'] != $info['access_id']) {
      $items[$info['access_type_id']] = $info['access_id'];
    }
    else {
      $items[$info['access_type_id']] = 0;
    }
  }
  else {
    foreach (array_filter($info['access_type_id']) as $key) {
      $items[$key] = 0;
    }
  }
  $tree = array();
  foreach ($items as $name => $mlid) {
    $data = menu_load($name);
    if (empty($data['menu_name'])) {
      break;
    }
    if ($mlid == 0) {
      $tree[$name] = array(
        'access_id' => $data['menu_name'],
        'access_type_id' => $data['menu_name'],
        'name' => $data['title'],
        'description' => $data['description'],
        'weight' => 0,
        'depth' => 0,
        'parent' => 0,
      );
      $mlid = TRUE;
    }

    // This call returns a nested array.
    // @todo, given the use of a private function here, we might need our
    // own lookup instead.
    $menu = _menu_build_tree($name);
    foreach ($menu['tree'] as $link) {

      // Ensure that we start at the top of the current request.
      // If mlid is TRUE, we are at the root.
      _workbench_access_menu_build_tree($tree, $link, $mlid);
    }
  }
  if ($keys) {
    return array_keys($tree);
  }
  return $tree;
}