You are here

private function HierarchyManager::hierarchyFlattenTree in Entity Reference Hierarchy 8

Recursively convert the tree to a flattened list (with depth)

Parameters

$nodes: The list of nodes to process

int $depth: The depth of the list

Return value

array The flattened list to be used in the dropdown selector of available parent nodes.

See also

hierarchyParentOptions

1 call to HierarchyManager::hierarchyFlattenTree()
HierarchyManager::hierarchyParentOptions in src/HierarchyManager.php
Return a list of valid possible hierarchy parents for the given child node type. This list is passed back to hierarchyGetParentSelector so it can be displayed as a dropdown selection list.

File

src/HierarchyManager.php, line 584
Contains \Drupal\entity_hierarchy\HierarchyManager.

Class

HierarchyManager
Defines a hierarchy manager.

Namespace

Drupal\entity_hierarchy

Code

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

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