You are here

public function TaxonomyTermTree::load in Organigrams 8

Same name and namespace in other branches
  1. 8.2 src/TaxonomyTermTree.php \Drupal\organigrams\TaxonomyTermTree::load()

Loads the tree of a vocabulary.

Parameters

string $vocabulary: Contains the vocabulary machine name.

Return value

array Contains the taxonomy tree.

File

src/TaxonomyTermTree.php, line 52

Class

TaxonomyTermTree
Loads taxonomy terms in a tree.

Namespace

Drupal\organigrams

Code

public function load($vocabulary) {

  // Load all terms of the vocabulary.
  $terms = $this->entityTypeManager
    ->getStorage('taxonomy_term')
    ->loadTree($vocabulary, 0, NULL, TRUE);

  // Define the tree array and iterate through the terms to fill it.
  $tree = [];
  foreach ($terms as $tree_object) {
    $this
      ->buildTree($tree, $tree_object, $vocabulary);
  }
  return $tree;
}