// We request N+1 items to find out if there is a next page for the pager.
// We may need to remove that extra item before loading the entities.
$pager_size =
$query->
getMetaData('pager_size'
);
if ($has_next_page =
$pager_size <
count($results)) { // Drop the last result.
array_pop($results);
} // Each item of the collection data contains an array with 'entity' and
// 'access' elements.
$collection_data =
$this->
loadEntitiesWithAccess($storage,
$results,
$request->
get(ResourceVersionRouteEnhancer::WORKING_COPIES_REQUESTED, FALSE
));
$primary_data =
new ResourceObjectData($collection_data);
$primary_data->
setHasNextPage($has_next_page);
// Calculate all the results and pass into a JSON:API Data object.
$count_query_cacheability =
new CacheableMetadata();
if ($resource_type->
includeCount()) { $count_query =
$this->
getCollectionCountQuery($resource_type,
$params,
$count_query_cacheability);
$total_results =
$this->
executeQueryInRenderContext( $count_query,
$count_query_cacheability );
$primary_data->
setTotalCount($total_results);
}