You are here

function _workbench_access_menu_build_tree in Workbench Access 7

Recursive helper function to build menus.

Parameters

&$tree: The workbench access tree being built.

$link: The menu link being inspected.

$mlid: The menu link id being acted upon. May be 0 if this is the top-level menu item. Switches to TRUE so that children of a matching item can be selected.

1 call to _workbench_access_menu_build_tree()
menu_workbench_access_tree in modules/menu.workbench_access.inc
Implements hook_workbench_access_tree().

File

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

Code

function _workbench_access_menu_build_tree(&$tree, $link, $mlid = 0) {
  $item = (object) $link['link'];

  // If the item matches the expected link id, or is the top-level, continue.
  if ($item->mlid == $mlid || $mlid === TRUE) {
    $tree[$item->mlid] = array(
      'access_id' => $item->mlid,
      'access_type_id' => $item->menu_name,
      'name' => $item->link_title,
      'description' => isset($item->options['attributes']['title']) ? $item->options['attributes']['title'] : '',
      'weight' => $item->weight,
      'depth' => $item->depth,
      'parent' => $item->plid == 0 ? $item->menu_name : $item->plid,
    );

    // Access to the parent grants access to the children.
    $mlid = TRUE;
  }

  // menu_tree_all_data() returns a nested array, so if we don't start at the
  // top level of the tree, then we must check below links individually.
  if (!empty($link['below'])) {

    // The elements of the 'below' sub-array are not sorted by weight.
    uasort($link['below'], '_workbench_access_menu_sort');
    foreach ($link['below'] as $below) {
      _workbench_access_menu_build_tree($tree, $below, $mlid);
    }
  }
}