public function WebformEntityReferenceTrait::getTargetEntities in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformEntityReferenceTrait.php \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::getTargetEntities()
1 call to WebformEntityReferenceTrait::getTargetEntities()
- WebformEntityReferenceTrait::getTargetEntity in src/
Plugin/ WebformElement/ WebformEntityReferenceTrait.php
File
- src/
Plugin/ WebformElement/ WebformEntityReferenceTrait.php, line 425
Class
- WebformEntityReferenceTrait
- Provides an 'entity_reference' trait.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function getTargetEntities(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
if (empty($value)) {
return [];
}
if (!is_array($value)) {
$value = [
$value,
];
}
$target_type = $this
->getTargetType($element);
$entities = $this->entityTypeManager
->getStorage($target_type)
->loadMultiple($value);
foreach ($entities as $entity_id => $entity) {
// Set the entity in the correct language for display.
$entities[$entity_id] = $this->entityRepository
->getTranslationFromContext($entity);
}
return $entities;
}