You are here

public function RenderCheeseburgerMenuBlock::getVocabularyTree in Cheeseburger Menu 8.4

Formats vocabulary.

File

src/Controller/RenderCheeseburgerMenuBlock.php, line 424
Controller used for rendering block.

Class

RenderCheeseburgerMenuBlock
Class RenderCheeseburgerMenuBlock.

Namespace

Drupal\cheeseburger_menu\Controller

Code

public function getVocabularyTree($vocabulary) {
  $vocabulary_tree = $this
    ->entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadTree($vocabulary);
  $tree = [];
  $parents = [];
  foreach ($vocabulary_tree as $term) {
    if (reset($term->parents) == 0) {
      $parents[] = $term;
    }
  }
  foreach ($parents as $term) {
    $tree[] = $this
      ->findVocabularyChild($this
      ->entityTypeManager()
      ->getStorage('taxonomy_term')
      ->load($term->tid));
  }
  return $tree;
}