You are here

protected function EntityQueryEntities::resolveEntities in GraphQL 8.3

Resolves entity objects and checks view permissions.

Parameters

array $entities: The entities to resolve.

mixed $metadata: The query context.

array $args: The field arguments array.

\Drupal\graphql\GraphQL\Execution\ResolveContext $context: The resolve context.

\GraphQL\Type\Definition\ResolveInfo $info: The resolve info object.

Return value

\Generator The resolved entities.

2 calls to EntityQueryEntities::resolveEntities()
EntityQueryEntities::resolveFromEntityIds in modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQueryEntities.php
Resolves entities lazily through the entity buffer.
EntityQueryEntities::resolveFromRevisionIds in modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQueryEntities.php
Resolves entity revisions.

File

modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQueryEntities.php, line 199

Class

EntityQueryEntities
Retrieve the entity result set of an entity query.

Namespace

Drupal\graphql_core\Plugin\GraphQL\Fields\EntityQuery

Code

protected function resolveEntities(array $entities, $metadata, array $args, ResolveContext $context, ResolveInfo $info) {
  $language = $this
    ->negotiateLanguage($metadata, $args, $context, $info);

  /** @var \Drupal\Core\Entity\EntityInterface $entity */
  foreach ($entities as $entity) {

    // Translate the entity if it is translatable and a language was given.
    if ($language && $entity instanceof TranslatableInterface && $entity
      ->isTranslatable()) {
      if ($entity
        ->hasTranslation($language)) {
        $entity = $entity
          ->getTranslation($language);
      }
    }
    $access = $entity
      ->access('view', NULL, TRUE);
    if ($access
      ->isAllowed()) {
      (yield $entity
        ->addCacheableDependency($access));
    }
    else {
      (yield new CacheableValue(NULL, [
        $access,
      ]));
    }
  }
}