You are here

private function HierarchicalTaxonomyMenuBlock::getEntityIdsForTerm in Hierarchical Taxonomy Menu 8

Gets entities referencing the given term.

1 call to HierarchicalTaxonomyMenuBlock::getEntityIdsForTerm()
HierarchicalTaxonomyMenuBlock::getEntityIds in src/Plugin/Block/HierarchicalTaxonomyMenuBlock.php
Gets all entities referencing the given term.

File

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

Class

HierarchicalTaxonomyMenuBlock
Provides a 'HierarchicalTaxonomyMenuBlock' block.

Namespace

Drupal\hierarchical_taxonomy_menu\Plugin\Block

Code

private function getEntityIdsForTerm($entity_type_id, $field_name, $tid) {
  if (empty($field_name)) {
    return [];
  }
  if ($entity_type_id == 'node') {
    return $this->database
      ->select('taxonomy_index', 'ta')
      ->fields('ta', [
      'nid',
    ])
      ->distinct(TRUE)
      ->condition('tid', $tid)
      ->execute()
      ->fetchCol();
  }
  else {
    return $this->database
      ->select('commerce_product__' . $field_name, 'cp')
      ->fields('cp', [
      'entity_id',
    ])
      ->distinct(TRUE)
      ->condition($field_name . '_target_id', $tid)
      ->execute()
      ->fetchCol();
  }
}