protected function iterBranch(TaxonomyTermInterface $term, $maxDepth) { $currDepth = 0; while ($term->hasParent()) { if ($term->isTrashed()) { return $maxDepth; } $term = $term->getParent(); $currDepth++; if ($currDepth >= $maxDepth) { return $currDepth; } } return $currDepth; }