public function SelectionBase::buildEntityQuery

Builds an EntityQuery to get referencable 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.

7 calls to SelectionBase::buildEntityQuery()
CommentSelection::buildEntityQuery in drupal/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php
Overrides SelectionBase::buildEntityQuery().
FileSelection::buildEntityQuery in drupal/core/modules/file/lib/Drupal/file/Plugin/entity_reference/selection/FileSelection.php
Overrides SelectionBase::buildEntityQuery().
NodeSelection::buildEntityQuery in drupal/core/modules/node/lib/Drupal/node/Plugin/entity_reference/selection/NodeSelection.php
Overrides SelectionBase::buildEntityQuery().
SelectionBase::countReferencableEntities in drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php
Implements SelectionInterface::countReferencableEntities().
SelectionBase::getReferencableEntities in drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php
Implements SelectionInterface::getReferencableEntities().

... See full list

4 methods override SelectionBase::buildEntityQuery()
CommentSelection::buildEntityQuery in drupal/core/modules/comment/lib/Drupal/comment/Plugin/entity_reference/selection/CommentSelection.php
Overrides SelectionBase::buildEntityQuery().
FileSelection::buildEntityQuery in drupal/core/modules/file/lib/Drupal/file/Plugin/entity_reference/selection/FileSelection.php
Overrides SelectionBase::buildEntityQuery().
NodeSelection::buildEntityQuery in drupal/core/modules/node/lib/Drupal/node/Plugin/entity_reference/selection/NodeSelection.php
Overrides SelectionBase::buildEntityQuery().
UserSelection::buildEntityQuery in drupal/core/modules/user/lib/Drupal/user/Plugin/entity_reference/selection/UserSelection.php
Overrides SelectionBase::buildEntityQuery().

File

drupal/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php, line 266
Contains \Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase.

Class

SelectionBase
Plugin implementation of the 'selection' entity_reference.

Namespace

Drupal\entity_reference\Plugin\entity_reference\selection

Code

public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
  $target_type = $this->field['settings']['target_type'];
  $entity_info = entity_get_info($target_type);
  $query = \Drupal::entityQuery($target_type);
  if (!empty($this->instance['settings']['handler_settings']['target_bundles'])) {
    $query
      ->condition($entity_info['entity_keys']['bundle'], $this->instance['settings']['handler_settings']['target_bundles'], 'IN');
  }
  if (isset($match) && isset($entity_info['entity_keys']['label'])) {
    $query
      ->condition($entity_info['entity_keys']['label'], $match, $match_operator);
  }

  // Add entity-access tag.
  $query
    ->addTag($this->field['settings']['target_type'] . '_access');

  // Add the Selection handler for
  // entity_reference_query_entity_reference_alter().
  $query
    ->addTag('entity_reference');
  $query
    ->addMetaData('field', $this->field);
  $query
    ->addMetaData('entity_reference_selection_handler', $this);

  // Add the sort option.
  if (!empty($this->instance['settings']['handler_settings']['sort'])) {
    $sort_settings = $this->instance['settings']['handler_settings']['sort'];
    if ($sort_settings['field'] != '_none') {
      $query
        ->sort($sort_settings['field'], $sort_settings['direction']);
    }
  }
  return $query;
}