You are here

protected function EntityReferenceIntegrityEntityHandler::referentialEntityQuery in Entity Reference Integrity 8

Start an entity query for entities matching set conditions.

Query for all entities of the specified type which have any fields in the source field list that match the given target ID.

Parameters

string $entity_type: The entityt type.

array $source_fields: An array of source fields.

string|int $target_id: The target ID to search for.

Return value

\Drupal\Core\Entity\Query\QueryInterface A query object.

File

src/EntityReferenceIntegrityEntityHandler.php, line 115

Class

EntityReferenceIntegrityEntityHandler
Entity reference integrity entity handler.

Namespace

Drupal\entity_reference_integrity

Code

protected function referentialEntityQuery($entity_type, array $source_fields, $target_id) {
  $query = $this->entityTypeManager
    ->getStorage($entity_type)
    ->getQuery();
  $or_group = $query
    ->orConditionGroup();
  foreach ($source_fields as $source_field) {
    $or_group
      ->condition($source_field, $target_id, '=');
  }
  $query
    ->condition($or_group);
  return $query;
}