public function ProductVariationSelection::getReferenceableEntities in Commerce Core 8.2
Gets the list of referenceable entities.
Return value
array A nested array of entities, the first level is keyed by the entity bundle, which contains an array of entity labels (escaped), keyed by the entity ID.
Overrides DefaultSelection::getReferenceableEntities
File
- modules/
product/ src/ Plugin/ EntityReferenceSelection/ ProductVariationSelection.php, line 60
Class
- ProductVariationSelection
- Enables product variation selection by title or SKU.
Namespace
Drupal\commerce_product\Plugin\EntityReferenceSelectionCode
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
$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('commerce_product_variation')
->loadMultiple($result);
/** @var \Drupal\commerce_product\Entity\ProductVariationInterface $entity */
foreach ($entities as $entity_id => $entity) {
$bundle = $entity
->bundle();
$options[$bundle][$entity_id] = Html::escape($entity
->getSku() . ': ' . $this->entityRepository
->getTranslationFromContext($entity)
->label());
}
return $options;
}