You are here

protected function EntityResource::getJsonApiParams in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getJsonApiParams()
  2. 10 core/modules/jsonapi/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 JSON:API resource type.

Return value

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

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

File

core/modules/jsonapi/src/Controller/EntityResource.php, line 1209

Class

EntityResource
Process all entity requests.

Namespace

Drupal\jsonapi\Controller

Code

protected function getJsonApiParams(Request $request, ResourceType $resource_type) {
  if ($request->query
    ->has('filter')) {
    $params[Filter::KEY_NAME] = Filter::createFromQueryParameter($request->query
      ->get('filter'), $resource_type, $this->fieldResolver);
  }
  if ($request->query
    ->has('sort')) {
    $params[Sort::KEY_NAME] = Sort::createFromQueryParameter($request->query
      ->get('sort'));
  }
  if ($request->query
    ->has('page')) {
    $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter($request->query
      ->get('page'));
  }
  else {
    $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter([
      'page' => [
        'offset' => OffsetPage::DEFAULT_OFFSET,
        'limit' => OffsetPage::SIZE_MAX,
      ],
    ]);
  }
  return $params;
}