function DefaultSelection::buildEntityQuery
Builds an EntityQuery to get referenceable entities.
Parameters
string|null $match: (Optional) Text to match the label against. Defaults to NULL.
string $match_operator: (Optional) The operation the matching should be done with. Defaults to "CONTAINS".
Return value
\Drupal\Core\Entity\Query\QueryInterface The EntityQuery object with the basic conditions and sorting applied to it.
10 calls to DefaultSelection::buildEntityQuery()
- CommentSelection::buildEntityQuery in core/modules/ comment/ src/ Plugin/ EntityReferenceSelection/ CommentSelection.php 
- Builds an EntityQuery to get referenceable entities.
- DefaultSelection::countReferenceableEntities in core/lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php 
- Counts entities that are referenceable.
- DefaultSelection::getReferenceableEntities in core/lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php 
- Gets the list of referenceable entities.
- DefaultSelection::validateReferenceableEntities in core/lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php 
- Validates which existing entities can be referenced.
- FileSelection::buildEntityQuery in core/modules/ file/ src/ Plugin/ EntityReferenceSelection/ FileSelection.php 
- Builds an EntityQuery to get referenceable entities.
7 methods override DefaultSelection::buildEntityQuery()
- CommentSelection::buildEntityQuery in core/modules/ comment/ src/ Plugin/ EntityReferenceSelection/ CommentSelection.php 
- Builds an EntityQuery to get referenceable entities.
- FileSelection::buildEntityQuery in core/modules/ file/ src/ Plugin/ EntityReferenceSelection/ FileSelection.php 
- Builds an EntityQuery to get referenceable entities.
- MediaSelection::buildEntityQuery in core/modules/ media/ src/ Plugin/ EntityReferenceSelection/ MediaSelection.php 
- Builds an EntityQuery to get referenceable entities.
- NodeSelection::buildEntityQuery in core/modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php 
- Builds an EntityQuery to get referenceable entities.
- TermSelection::buildEntityQuery in core/modules/ taxonomy/ src/ Plugin/ EntityReferenceSelection/ TermSelection.php 
- Builds an EntityQuery to get referenceable entities.
File
- 
              core/lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php, line 437 
Class
- DefaultSelection
- Default plugin implementation of the Entity Reference Selection plugin.
Namespace
Drupal\Core\Entity\Plugin\EntityReferenceSelectionCode
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
  $configuration = $this->getConfiguration();
  $target_type = $configuration['target_type'];
  $entity_type = $this->entityTypeManager
    ->getDefinition($target_type);
  $query = $this->entityTypeManager
    ->getStorage($target_type)
    ->getQuery();
  $query->accessCheck(TRUE);
  // If 'target_bundles' is NULL, all bundles are referenceable, no further
  // conditions are needed.
  if (is_array($configuration['target_bundles'])) {
    // If 'target_bundles' is an empty array, no bundle is referenceable,
    // force the query to never return anything and bail out early.
    if ($configuration['target_bundles'] === []) {
      $query->condition($entity_type->getKey('id'), NULL, '=');
      return $query;
    }
    else {
      $query->condition($entity_type->getKey('bundle'), $configuration['target_bundles'], 'IN');
    }
  }
  if (isset($match) && $label_key = $entity_type->getKey('label')) {
    $query->condition($label_key, $match, $match_operator);
  }
  // Add entity-access tag.
  $query->addTag($target_type . '_access');
  // Add the Selection handler for system_query_entity_reference_alter().
  $query->addTag('entity_reference');
  $query->addMetaData('entity_reference_selection_handler', $this);
  // Add the sort option.
  if ($configuration['sort']['field'] !== '_none') {
    $query->sort($configuration['sort']['field'], $configuration['sort']['direction']);
  }
  return $query;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
