You are here

public function FeaturedNodes::process in JSON:API Resources 8

Process the resource request.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request.

Return value

\Drupal\jsonapi\ResourceResponse The response.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

tests/modules/jsonapi_resources_test/src/Resource/FeaturedNodes.php, line 31

Class

FeaturedNodes
Processes a request for a collection of featured nodes.

Namespace

Drupal\jsonapi_resources_test\Resource

Code

public function process(Request $request) : ResourceResponse {
  $query = $this
    ->getEntityQuery('node')
    ->condition('status', NodeInterface::PUBLISHED)
    ->condition('promote', NodeInterface::PROMOTED);
  $cacheability = new CacheableMetadata();
  $paginator = $this
    ->getPaginatorForRequest($request);
  $paginator
    ->applyToQuery($query, $cacheability);
  $data = $this
    ->loadResourceObjectDataFromEntityQuery($query, $cacheability);
  $pagination_links = $paginator
    ->getPaginationLinks($query, $cacheability);
  return $this
    ->createJsonapiResponse($data, $request, 200, [], $pagination_links);
}