getParameter('taxonomy_term'); if (!$term instanceof TermInterface) { return NULL; } if (!$this->handlesEntity($term)) { return NULL; } return $term; } /** * {@inheritdoc} */ public function buildBreadcrumb(Breadcrumb $breadcrumb, EntityInterface $entity): void { if (!$entity instanceof TermInterface) { return; } // Add all ancestors in the taxonomy hierarchy. $term_storage = $this->entityTypeManager->getStorage('taxonomy_term'); $ancestors = $term_storage->loadAllParents($entity->id()); $ancestors = array_reverse($ancestors); foreach ($ancestors as $ancestor) { $breadcrumb->addCacheableDependency($ancestor); $breadcrumb->addLink($ancestor->toLink()); } } /** * {@inheritdoc} */ public function handlesEntity(EntityInterface $entity): bool { if ($entity->getEntityTypeId() !== 'taxonomy_term') { return FALSE; } $vocabulary = \Drupal::config('structural_pages.settings') ->get('site_section_vocabulary') ?? 'site_sections'; return $entity->bundle() === $vocabulary; } /** * {@inheritdoc} */ public function getSiteSectionId(EntityInterface $entity): int|string|null { if (!$entity instanceof TermInterface) { return NULL; } if (!$this->handlesEntity($entity)) { return NULL; } return $entity->id(); } }