You are here

private function ReferenceFinder::loadReferencingEntitiesOfType in Term reference change 8

Loads all entities of a given type with reference to the given term.

Parameters

\Drupal\taxonomy\TermInterface $term: The term to find references to.

array $bundles: The entity bundles that might contain these references.

string $entityType: The entity type to limit to.

Return value

array The loaded entities.

1 call to ReferenceFinder::loadReferencingEntitiesOfType()
ReferenceFinder::loadReferencingEntities in src/ReferenceFinder.php
Loads all entities with a reference to the given term.

File

src/ReferenceFinder.php, line 100

Class

ReferenceFinder
Finds entities referencing a term.

Namespace

Drupal\term_reference_change

Code

private function loadReferencingEntitiesOfType(TermInterface $term, array $bundles, $entityType) {
  $referencingEntities = [];
  foreach ($bundles as $bundle) {
    foreach ($bundle as $fieldName) {
      $entities = $this->entityTypeManager
        ->getStorage($entityType)
        ->loadByProperties([
        $fieldName => $term
          ->id(),
      ]);
      $referencingEntities = array_merge($referencingEntities, $entities);
    }
  }
  return $referencingEntities;
}