You are here

function workbench_access_options in Workbench Access 7

Build form options from a tree.

Parameters

$tree: The current access tree.

$active: An array of active sections, used as a filter.

Return value

An array of options, suitable for use in a form.

2 calls to workbench_access_options()
workbench_access_active_options in ./workbench_access.module
Build an array of form options for the currently active workbench access tree.
workbench_access_node_operations in ./workbench_access.module
Implements hook_node_operations().

File

./workbench_access.module, line 1309
Workbench Access module file.

Code

function workbench_access_options($tree, $active) {
  $used = array();
  $parent = 0;
  $base_depth = 0;
  $options = array();
  if (empty($tree) || empty($active)) {
    return $options;
  }
  $tree_keys = array_keys($tree);
  $active_keys = array_flip(array_keys($active));
  foreach ($tree as $section) {
    if (in_array($section['access_id'], $used) || !isset($active_keys[$section['access_id']])) {
      continue;
    }

    // Nest the children so the user understands the hierarchy.
    if ($section['depth'] == 0 || !isset($tree[$section['parent']])) {
      $parent = $section['name'];
      $base_depth = $section['depth'];
    }
    $options[$section['access_id']] = str_repeat('-', $section['depth'] - $base_depth) . ' ' . $section['name'];
    $used[] = $section['access_id'];
  }
  return $options;
}