function DefaultSelection::buildEntityQuery

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::buildEntityQuery()
  2. 10 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::buildEntityQuery()
  3. 11.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\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.

... See full list

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.

... See full list

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php, line 442

Class

DefaultSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

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();
    // 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.