diff --git a/src/Plugin/facets/hierarchy/Taxonomy.php b/src/Plugin/facets/hierarchy/Taxonomy.php index c4728ac..1f33838 100644 --- a/src/Plugin/facets/hierarchy/Taxonomy.php +++ b/src/Plugin/facets/hierarchy/Taxonomy.php @@ -2,8 +2,6 @@ namespace Drupal\facets\Plugin\facets\hierarchy; -use Drupal\Core\Database\Connection; -use Drupal\Core\Database\Query\Condition; use Drupal\facets\Hierarchy\HierarchyPluginBase; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\TermStorageInterface; @@ -72,11 +70,15 @@ class Taxonomy extends HierarchyPluginBase { * {@inheritdoc} */ public function getNestedChildIds($id) { - $children = &drupal_static(__FUNCTION__, []); - if (!isset($children[$id])) { - $term = Term::load($id)->getVocabularyId(); - $children = $this->termStorage->loadTree($term, $id); + $children = $this->termStorage->loadChildren($id); + $subchilds = []; + $children = array_filter(array_values(array_map(function ($it) { + return $it->id(); + }, $children))); + foreach ($children as $child) { + $subchilds = array_merge($subchilds, $this->getNestedChildIds($child)); } + $children[$id] = array_merge($children, $subchilds); return isset($children[$id]) ? $children[$id] : []; } @@ -105,16 +107,13 @@ class Taxonomy extends HierarchyPluginBase { * Returns FALSE if no parent is found, else parent tid. */ protected function taxonomyGetParent($tid) { - $parent = &drupal_static(__FUNCTION__, []); $parent = []; - if (!isset($parent[$tid])) { - $parents = $this->termStorage->loadParents($tid); - if (empty($parents)) { - return FALSE; - } - $parent[$tid] = reset($parents)->id(); + $parents = $this->termStorage->loadParents($tid); + if (empty($parents)) { + return FALSE; } + $parent[$tid] = reset($parents)->id(); return isset($parent[$tid]) ? $parent[$tid] : FALSE; }