private function EntityReferenceTrait::filterAccessible in GraphQL 8.4
Filter out not accessible entities.
Parameters
\Drupal\Core\Entity\EntityInterface[] $entities: Entities to filter.
\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.
\Drupal\graphql\GraphQL\Execution\FieldContext $context: The caching context related to the current field.
Return value
\Drupal\Core\Entity\EntityInterface[] Filtered entities.
1 call to EntityReferenceTrait::filterAccessible()
- 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 102
Class
- EntityReferenceTrait
- Entity reference helpers.
Namespace
Drupal\graphql\Plugin\GraphQL\DataProducer\FieldCode
private function filterAccessible(array $entities, ?AccountInterface $accessUser, string $accessOperation, FieldContext $context) : array {
return array_filter($entities, function (EntityInterface $entity) use ($accessOperation, $accessUser, $context) {
/** @var \Drupal\Core\Access\AccessResultInterface $accessResult */
$accessResult = $entity
->access($accessOperation, $accessUser, TRUE);
$context
->addCacheableDependency($accessResult);
if (!$accessResult
->isAllowed()) {
return FALSE;
}
return TRUE;
});
}