protected function DefaultSelection::buildEntityQuery in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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.
7 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.
4 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.
- NodeSelection::buildEntityQuery in core/
modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php - Builds an EntityQuery to get referenceable entities.
- UserSelection::buildEntityQuery in core/
modules/ user/ src/ Plugin/ EntityReferenceSelection/ UserSelection.php - Builds an EntityQuery to get referenceable entities.
File
- core/
lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php, line 338 - Contains \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection.
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') {
$target_type = $this->configuration['target_type'];
$handler_settings = $this->configuration['handler_settings'];
$entity_type = $this->entityManager
->getDefinition($target_type);
$query = $this->entityManager
->getStorage($target_type)
->getQuery();
// If 'target_bundles' is NULL, all bundles are referenceable, no further
// conditions are needed.
if (isset($handler_settings['target_bundles']) && is_array($handler_settings['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 ($handler_settings['target_bundles'] === []) {
$query
->condition($entity_type
->getKey('id'), NULL, '=');
return $query;
}
else {
$query
->condition($entity_type
->getKey('bundle'), $handler_settings['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 (!empty($handler_settings['sort'])) {
$sort_settings = $handler_settings['sort'];
if ($sort_settings['field'] != '_none') {
$query
->sort($sort_settings['field'], $sort_settings['direction']);
}
}
return $query;
}