You are here

protected function EntityResource::respondWithCollection in JSON:API 8

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

Respond with an entity collection.

Parameters

\Drupal\jsonapi\Resource\EntityCollection $entity_collection: The collection of entites.

string $entity_type_id: The entity type.

Return value

\Drupal\jsonapi\ResourceResponse The response.

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

File

src/Controller/EntityResource.php, line 909

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected function respondWithCollection(EntityCollection $entity_collection, $entity_type_id) {
  $response = $this
    ->buildWrappedResponse($entity_collection);

  // When a new change to any entity in the resource happens, we cannot ensure
  // the validity of this cached list. Add the list tag to deal with that.
  $list_tag = $this->entityTypeManager
    ->getDefinition($entity_type_id)
    ->getListCacheTags();
  $response
    ->getCacheableMetadata()
    ->addCacheTags($list_tag);
  return $response;
}