function DefaultSelection::getReferenceableEntities

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::getReferenceableEntities()
  2. 8.9.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::getReferenceableEntities()
  3. 10 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::getReferenceableEntities()

Overrides SelectionInterface::getReferenceableEntities

3 calls to DefaultSelection::getReferenceableEntities()
PhpSelection::getReferenceableEntities in core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php
Gets the list of referenceable entities.
TermSelection::getReferenceableEntities in core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
Gets the list of referenceable entities.
WorkspaceSelection::getReferenceableEntities in core/modules/workspaces/src/Plugin/EntityReferenceSelection/WorkspaceSelection.php
Gets the list of referenceable entities.
4 methods override DefaultSelection::getReferenceableEntities()
CommentSelection::getReferenceableEntities in core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php
Gets the list of referenceable entities.
PhpSelection::getReferenceableEntities in core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/PhpSelection.php
Gets the list of referenceable entities.
TermSelection::getReferenceableEntities in core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
Gets the list of referenceable entities.
WorkspaceSelection::getReferenceableEntities in core/modules/workspaces/src/Plugin/EntityReferenceSelection/WorkspaceSelection.php
Gets the list of referenceable entities.

File

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

Class

DefaultSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    $target_type = $this->getConfiguration()['target_type'];
    $query = $this->buildEntityQuery($match, $match_operator);
    if ($limit > 0) {
        $query->range(0, $limit);
    }
    $result = $query->execute();
    if (empty($result)) {
        return [];
    }
    $options = [];
    $entities = $this->entityTypeManager
        ->getStorage($target_type)
        ->loadMultiple($result);
    foreach ($entities as $entity_id => $entity) {
        $bundle = $entity->bundle();
        $options[$bundle][$entity_id] = Html::escape($this->entityRepository
            ->getTranslationFromContext($entity)
            ->label() ?? '');
    }
    return $options;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.