protected function ProductVariationSelection::buildEntityQuery in Commerce Core 8.2
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.
Overrides DefaultSelection::buildEntityQuery
1 call to ProductVariationSelection::buildEntityQuery()
- ProductVariationSelection::getReferenceableEntities in modules/
product/ src/ Plugin/ EntityReferenceSelection/ ProductVariationSelection.php - Gets the list of referenceable entities.
File
- modules/
product/ src/ Plugin/ EntityReferenceSelection/ ProductVariationSelection.php, line 24
Class
- ProductVariationSelection
- Enables product variation selection by title or SKU.
Namespace
Drupal\commerce_product\Plugin\EntityReferenceSelectionCode
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$configuration = $this
->getConfiguration();
$query = $this->entityTypeManager
->getStorage('commerce_product_variation')
->getQuery();
if (!empty($configuration['target_bundles'])) {
$query
->condition('type', $configuration['target_bundles'], 'IN');
}
if (isset($match)) {
$match_condition = $query
->orConditionGroup()
->condition('title', $match, $match_operator)
->condition('sku', $match, $match_operator);
$query
->condition($match_condition);
}
// Add entity-access tag.
$query
->accessCheck(TRUE)
->addTag('commerce_product_variation_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;
}