You are here

protected function Taxonomy::buildTree in Workbench Access 8

Traverses the taxonomy tree and builds parentage arrays.

Note: this method is necessary to load all parents to the array.

Parameters

string $id: The root id of the section tree.

array $data: An array of menu tree or subtree data.

array &$tree: The computed tree array to return.

Return value

array The compiled tree data.

1 call to Taxonomy::buildTree()
Taxonomy::getTree in src/Plugin/AccessControlHierarchy/Taxonomy.php
Gets the entire hierarchy tree.

File

src/Plugin/AccessControlHierarchy/Taxonomy.php, line 147

Class

Taxonomy
Defines a hierarchy based on a Vocabulary.

Namespace

Drupal\workbench_access\Plugin\AccessControlHierarchy

Code

protected function buildTree($id, array $data, array &$tree) {
  foreach ($data as $term) {
    $tree[$id][$term->tid] = [
      'id' => $term->tid,
      'label' => $term->name,
      'depth' => $term->depth + 1,
      'parents' => $this
        ->convertParents($term, $id),
      'weight' => $term->weight,
      'description' => $term->description__value,
      'path' => Url::fromUri('entity:taxonomy_term/' . $term->tid)
        ->toString(),
    ];
    foreach ($tree[$id][$term->tid]['parents'] as $key) {
      if (!empty($tree[$id][$key]['parents'])) {
        $tree[$id][$term->tid]['parents'] = array_unique(array_merge($tree[$id][$key]['parents'], $tree[$id][$term->tid]['parents']));
      }
    }
  }
  return $tree;
}