protected function EntityReferenceTrait::getReferencedEntities in GraphQL 8.4
Retrieves referenced entities from the given resolver.
May optionally respect bundles/language and perform access checks.
Parameters
string $type: Entity type ID.
string|null $language: Optional. Language to be respected for retrieved entities.
array|null $bundles: Optional. List of bundles to be respected for retrieved entities.
bool $access: Whether to filter out inaccessible entities.
\Drupal\Core\Session\AccountInterface|null $accessUser: User entity to check access for. Default is null.
string $accessOperation: Operation to check access for. Default is view.
\Closure $resolver: The resolver to execute.
\Drupal\graphql\GraphQL\Execution\FieldContext $context: The caching context related to the current field.
Return value
\Drupal\Core\Entity\EntityInterface[]|null The list of references entities. Or NULL.
3 calls to EntityReferenceTrait::getReferencedEntities()
- EntityReference::resolve in src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReference.php - Resolve entity references in the given field name.
- EntityReferenceLayoutRevisions::resolve in src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceLayoutRevisions.php - Resolves entity reference layout revisions for a field of a given entity.
- EntityReferenceRevisions::resolve in src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceRevisions.php - Resolves entity reference revisions for a given field of a given entity.
File
- src/
Plugin/ GraphQL/ DataProducer/ Field/ EntityReferenceTrait.php, line 40
Class
- EntityReferenceTrait
- Entity reference helpers.
Namespace
Drupal\graphql\Plugin\GraphQL\DataProducer\FieldCode
protected function getReferencedEntities(string $type, ?string $language, ?array $bundles, bool $access, ?AccountInterface $accessUser, string $accessOperation, \Closure $resolver, FieldContext $context) : ?array {
$entities = $resolver() ?: [];
if (isset($bundles)) {
$entities = array_filter($entities, function (EntityInterface $entity) use ($bundles) {
return in_array($entity
->bundle(), $bundles);
});
}
if (isset($language)) {
$entities = $this
->getTranslated($entities, $language);
}
if ($access) {
$entities = $this
->filterAccessible($entities, $accessUser, $accessOperation, $context);
}
if (empty($entities)) {
$type = $this->entityTypeManager
->getDefinition($type);
/** @var \Drupal\Core\Entity\EntityTypeInterface $type */
$tags = $type
->getListCacheTags();
$context
->addCacheTags($tags);
return NULL;
}
return $entities;
}