protected function YamlFormEntityReferenceTrait::getTargetEntities in YAML Form 8
Get referenced entities.
Parameters
array $element: An element.
array|mixed $value: A value.
array $options: An array of options.
Return value
array|string A array containing $entity_ids and $entityies.
3 calls to YamlFormEntityReferenceTrait::getTargetEntities()
- YamlFormEntityReferenceTrait::formatItems in src/
Plugin/ YamlFormElement/ YamlFormEntityReferenceTrait.php - Format an entity autocomplete targets as array of strings.
- YamlFormEntityReferenceTrait::formatLinks in src/
Plugin/ YamlFormElement/ YamlFormEntityReferenceTrait.php - Format an entity autocomplete as a link or a list of links.
- YamlFormEntityReferenceTrait::formatView in src/
Plugin/ YamlFormElement/ YamlFormEntityReferenceTrait.php - Format an entity autocomplete targets using a view mode.
File
- src/
Plugin/ YamlFormElement/ YamlFormEntityReferenceTrait.php, line 367
Class
- YamlFormEntityReferenceTrait
- Provides an 'entity_reference' trait.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
protected function getTargetEntities(array $element, $value, array $options) {
$langcode = !empty($options['langcode']) ? $options['langcode'] : \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$entity_ids = $this
->getTargetEntityIds($value);
$entities = $this->entityTypeManager
->getStorage($element['#target_type'])
->loadMultiple($entity_ids);
foreach ($entities as $entity_id => $entity) {
if ($entity
->hasTranslation($langcode)) {
$entities[$entity_id] = $entity
->getTranslation($langcode);
}
}
return [
$entity_ids,
$entities,
];
}