protected function Vocabulary::buildList in Sitemap 2.0.x
Same name and namespace in other branches
- 8.2 src/Plugin/Sitemap/Vocabulary.php \Drupal\sitemap\Plugin\Sitemap\Vocabulary::buildList()
Builds a tree/list array given a taxonomy term tree object.
Parameters
array $list:
\stdClass $object:
string $vid:
int $currentDepth:
int $maxDepth:
See also
https://www.webomelette.com/loading-taxonomy-terms-tree-drupal-8
1 call to Vocabulary::buildList()
- Vocabulary::view in src/
Plugin/ Sitemap/ Vocabulary.php - Builds a renderable array for a sitemap item.
File
- src/
Plugin/ Sitemap/ Vocabulary.php, line 359
Class
- Vocabulary
- Provides a sitemap for an taxonomy vocabulary.
Namespace
Drupal\sitemap\Plugin\SitemapCode
protected function buildList(&$list, $object, $vid, &$currentDepth, $maxDepth) {
// Check that we are only working with the parent-most term.
if ($object->depth != 0) {
return;
}
// Track current depth of the term.
$object->treeDepth = $currentDepth;
// Check for children on the term.
// @TODO Implement $termStorage at the class level.
$termStorage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$children = $termStorage
->loadChildren($object->tid);
if (!$children) {
$object->hasChildren = FALSE;
if ($element = $this
->buildSitemapTerm($object)) {
$list[$object->tid][] = $element;
}
return;
}
else {
// If the term has children, it should always be displayed.
// TODO: That's not entirely accurate...
$object->display = TRUE;
$object->hasChildren = TRUE;
$list[$object->tid][] = $this
->buildSitemapTerm($object);
$list[$object->tid]['children'] = [];
$object_children =& $list[$object->tid]['children'];
}
$currentDepth++;
if ($maxDepth >= $currentDepth) {
$child_objects = $termStorage
->loadTree($vid, $object->tid, 1);
/** @var \Drupal\taxonomy\TermInterface[] $children */
foreach ($children as $child) {
foreach ($child_objects as $child_object) {
if ($child_object->tid == $child
->id()) {
$this
->buildlist($object_children, $child_object, $vid, $currentDepth, $maxDepth);
}
}
}
}
}