You are here

protected function EntityResource::getJsonApiParams in Drupal 10

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

File

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

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
      ->all('filter'), $resource_type, $this->fieldResolver);
  }
  if ($request->query
    ->has('sort')) {
    $params[Sort::KEY_NAME] = Sort::createFromQueryParameter($request->query
      ->all()['sort']);
  }
  if ($request->query
    ->has('page')) {
    $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter($request->query
      ->all('page'));
  }
  else {
    $params[OffsetPage::KEY_NAME] = OffsetPage::createFromQueryParameter([
      'page' => [
        'offset' => OffsetPage::DEFAULT_OFFSET,
        'limit' => OffsetPage::SIZE_MAX,
      ],
    ]);
  }
  return $params;
}