diff --git a/core/modules/taxonomy/src/Entity/Term.php b/core/modules/taxonomy/src/Entity/Term.php index 0850780..1b04b15 100644 --- a/core/modules/taxonomy/src/Entity/Term.php +++ b/core/modules/taxonomy/src/Entity/Term.php @@ -102,7 +102,6 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); - // Terms with no parents are mandatory children of . if (!$this->getParents()->count()) { $this->parent->target_id = 0; @@ -283,12 +282,10 @@ public function getAncestors() { $search[] = $this->id(); while ($tid = array_shift($search)) { - if ($parents = static::load($tid)->getParents()) { - foreach ($parents as $parent) { - if ($parent->target_id && !isset($this->ancestors[$parent->target_id])) { - $this->ancestors[$parent->target_id] = $parent->entity; - $search[] = $parent->target_id; - } + foreach (static::load($tid)->getParents() as $parent) { + if (!empty($parent->entity) && !isset($this->ancestors[$parent->target_id])) { + $this->ancestors[$parent->target_id] = $parent->entity; + $search[] = $parent->target_id; } } } diff --git a/core/modules/taxonomy/src/TermStorage.php b/core/modules/taxonomy/src/TermStorage.php index b147501..d42df53 100644 --- a/core/modules/taxonomy/src/TermStorage.php +++ b/core/modules/taxonomy/src/TermStorage.php @@ -181,7 +181,9 @@ public function loadTree($vid, $parent = 0, $max_depth = NULL, $load_entities = $term = clone $term; } $term->depth = $depth; - unset($term->parent); + if (!$load_entities) { + unset($term->parent); + } $tid = $load_entities ? $term->id() : $term->tid; $term->parents = $this->treeParents[$vid][$tid]; $tree[] = $term;