private function EntityReferenceTrait::getTranslated in GraphQL 8.4
Get the referenced entities in the specified language.
Parameters
\Drupal\Core\Entity\EntityInterface[] $entities: Entities to process.
string $language: Language to be respected for retrieved entities.
Return value
\Drupal\Core\Entity\EntityInterface[] Translated entities.
1 call to EntityReferenceTrait::getTranslated()
- EntityReferenceTrait::getReferencedEntities in src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceTrait.php - Retrieves referenced entities from the given resolver.
File
- src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceTrait.php, line 77
Class
- EntityReferenceTrait
- Entity reference helpers.
Namespace
Drupal\graphql\Plugin\GraphQL\DataProducer\FieldCode
private function getTranslated(array $entities, string $language) : array {
return array_map(function (EntityInterface $entity) use ($language) {
if ($language !== $entity
->language()
->getId() && $entity instanceof TranslatableInterface && $entity
->hasTranslation($language)) {
$entity = $entity
->getTranslation($language);
}
$entity
->addCacheContexts([
"static:language:{$language}",
]);
return $entity;
}, $entities);
}