You are here

protected static function EntityResource::getJsonApiParams in JSON:API 8

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

Extracts JSON:API query parameters from the request.

Parameters

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

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: The current JSON:API resoure type.

Return value

array An array of JSON:API parameters like `sort` and `filter`.

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

File

src/Controller/EntityResource.php, line 1131

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected static function getJsonApiParams(Request $request, ResourceType $resource_type) {
  $route_params = $request->attributes
    ->get('_route_params');
  $params = isset($route_params['_json_api_params']) ? $route_params['_json_api_params'] : [];
  if ($request->query
    ->has('filter')) {
    $serializer = \Drupal::service('jsonapi.serializer_do_not_use_removal_imminent');
    $context = [
      'entity_type_id' => $resource_type
        ->getEntityTypeId(),
      'bundle' => $resource_type
        ->getBundle(),
    ];
    $params[Filter::KEY_NAME] = $serializer
      ->denormalize($request->query
      ->get('filter'), Filter::class, NULL, $context);
  }
  return $params;
}