public function WebformEntityReferenceTrait::getTargetEntities in Webform 8.5
Same name and namespace in other branches
- 6.x 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 392
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,
];
}
/** @var \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
$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] = $entity_repository
->getTranslationFromContext($entity);
}
return $entities;
}