You are here

private function HierarchicalTaxonomyMenuBlock::getVocabularyBaseTerm in Hierarchical Taxonomy Menu 8

Returns base taxonomy term ID.

2 calls to HierarchicalTaxonomyMenuBlock::getVocabularyBaseTerm()
HierarchicalTaxonomyMenuBlock::build in src/Plugin/Block/HierarchicalTaxonomyMenuBlock.php
Builds and returns the renderable array for this block plugin.
HierarchicalTaxonomyMenuBlock::getCacheContexts in src/Plugin/Block/HierarchicalTaxonomyMenuBlock.php
The cache contexts associated with this object.

File

src/Plugin/Block/HierarchicalTaxonomyMenuBlock.php, line 824

Class

HierarchicalTaxonomyMenuBlock
Provides a 'HierarchicalTaxonomyMenuBlock' block.

Namespace

Drupal\hierarchical_taxonomy_menu\Plugin\Block

Code

private function getVocabularyBaseTerm($base_term, $dynamic_base_term) {
  if ($dynamic_base_term) {
    if ($term_id = $this->currentRouteMatch
      ->getRawParameter('taxonomy_term')) {
      return $term_id;
    }
    else {
      return 0;
    }
  }
  else {
    if (!$base_term) {
      return 0;
    }
    if (is_numeric($base_term)) {
      return $base_term;
    }
    else {
      $term = $this->entityTypeManager
        ->getStorage('taxonomy_term')
        ->loadByProperties([
        'name' => $base_term,
      ]);
      return $term ? reset($term)
        ->id() : 0;
    }
  }
}