You are here

protected function EntityResource::executeQueryInRenderContext in JSON:API 8

Same name and namespace in other branches
  1. 8.2 src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::executeQueryInRenderContext()

Executes the query in a render context, to catch bubbled cacheability.

@todo Remove this when the query sytems's return value is able to carry cacheability.

Parameters

\Drupal\Core\Entity\Query\QueryInterface $query: The query to execute to get the return results.

\Drupal\Core\Cache\CacheableMetadata $query_cacheability: The value object to carry the query cacheability.

Return value

int|array Returns an integer for count queries or an array of IDs. The values of the array are always entity IDs. The keys will be revision IDs if the entity supports revision and entity IDs if not.

See also

node_query_node_access_alter()

https://www.drupal.org/project/drupal/issues/2557815

https://www.drupal.org/project/drupal/issues/2794385

1 call to EntityResource::executeQueryInRenderContext()
EntityResource::getCollection in src/Controller/EntityResource.php
Gets the collection of entities.

File

src/Controller/EntityResource.php, line 441

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected function executeQueryInRenderContext(QueryInterface $query, CacheableMetadata $query_cacheability) {
  $context = new RenderContext();
  $results = $this->renderer
    ->executeInRenderContext($context, function () use ($query) {
    return $query
      ->execute();
  });
  if (!$context
    ->isEmpty()) {
    $query_cacheability
      ->addCacheableDependency($context
      ->pop());
  }
  return $results;
}