You are here

private function HierarchicalTaxonomyMenuBlock::getReferencingFields in Hierarchical Taxonomy Menu 8

Gets taxonomy term fields from commerce product entity.

Return value

array An array of taxonomy term fields.

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

File

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

Class

HierarchicalTaxonomyMenuBlock
Provides a 'HierarchicalTaxonomyMenuBlock' block.

Namespace

Drupal\hierarchical_taxonomy_menu\Plugin\Block

Code

private function getReferencingFields() {
  $referencing_fields = [];
  $referencing_fields['_none'] = $this
    ->t('- None -');
  $bundles = $this->entityTypeBundleInfo
    ->getBundleInfo('commerce_product');
  foreach ($bundles as $bundle => $data) {
    $fields = $this->entityFieldManager
      ->getFieldDefinitions('commerce_product', $bundle);

    /** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
    foreach ($fields as $field) {
      if ($field
        ->getType() == 'entity_reference' && $field
        ->getSetting('target_type') == 'taxonomy_term') {
        $referencing_fields[$field
          ->getName()] = $field
          ->getLabel();
      }
    }
  }
  return $referencing_fields;
}