You are here

private function HierarchicalTaxonomyMenuBlock::getVocabularyOptions in Hierarchical Taxonomy Menu 8

Generates vocabulary select options.

1 call to HierarchicalTaxonomyMenuBlock::getVocabularyOptions()
HierarchicalTaxonomyMenuBlock::blockForm in src/Plugin/Block/HierarchicalTaxonomyMenuBlock.php

File

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

Class

HierarchicalTaxonomyMenuBlock
Provides a 'HierarchicalTaxonomyMenuBlock' block.

Namespace

Drupal\hierarchical_taxonomy_menu\Plugin\Block

Code

private function getVocabularyOptions() {
  $options = [];
  $vocabularies = taxonomy_vocabulary_get_names();
  foreach ($vocabularies as $vocabulary) {
    $fields = $this->entityFieldManager
      ->getFieldDefinitions('taxonomy_term', $vocabulary);
    $options[$vocabulary . '|'] = $this
      ->t('@vocabulary (no image)', [
      '@vocabulary' => ucfirst($vocabulary),
    ]);
    foreach ($fields as $field) {
      if ($field
        ->getType() == 'image' || $this
        ->isMediaImage($field)) {
        $field_name = $field
          ->getName();
        $options[$vocabulary . '|' . $field_name] = $this
          ->t('@vocabulary (with image: @image_field)', [
          '@vocabulary' => ucfirst($vocabulary),
          '@image_field' => $field_name,
        ]);
      }
    }
  }
  return $options;
}