public function TaxonomyTermTree::loadList in Organigrams 8.2
Same name and namespace in other branches
- 8 src/TaxonomyTermTree.php \Drupal\organigrams\TaxonomyTermTree::loadList()
Loads the tree of a vocabulary and puts it in an item list.
Parameters
string $vocabulary: Contains the vocabulary machine name.
Return value
array Renderable array containing an item list.
File
- src/
TaxonomyTermTree.php, line 119
Class
- TaxonomyTermTree
- Loads taxonomy terms in a tree.
Namespace
Drupal\organigramsCode
public function loadList($vocabulary) {
// Get all taxonomy terms.
$terms = $this->entityTypeManager
->getStorage('taxonomy_term')
->loadTree($vocabulary, 0, NULL, TRUE);
// Set the positions to retreive.
$positions = [
'u',
's',
];
// Build a hierarchical taxonomy term array.
$items = [];
foreach ($terms as $tree_object) {
$this
->buildListTree($items, $tree_object, $vocabulary, $positions);
}
// Provide the ability to alter the taxonomy tree.
\Drupal::moduleHandler()
->alter('organigrams_taxonomy_term_tree', $items);
// Return an item list.
return [
'#theme' => 'item_list',
'#type' => 'ul',
'#attributes' => [
'class' => [
'orgchart',
'organigram-' . $vocabulary,
],
],
'#items' => $items,
];
}