You are here

function _nodehierarchy_flatten_tree in Node Hierarchy 7.4

Flatten the tree of nodes.

1 call to _nodehierarchy_flatten_tree()
_nodehierarchy_parent_options in ./nodehierarchy.admin.inc
Return a list of menu items that are valid possible parents for the given node.

File

./nodehierarchy.admin.inc, line 586
Admin functions for Node Hierarchy

Code

function _nodehierarchy_flatten_tree($nodes, $depth = 1) {
  $out = $children = array();
  foreach ($nodes as $nid => $node) {
    $node->depth = $depth;
    $children = array();
    if (!empty($node->children)) {
      $children = _nodehierarchy_flatten_tree($node->children, $depth + 1);
    }

    // Only output this option if there are non-disabled chidren.
    if (!$node->disabled || $children) {
      $out[$nid] = $node;
      $out += $children;
    }
  }
  return $out;
}