function EntityResource::getJsonApiParams

Same name in other branches
  1. 9 core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getJsonApiParams()
  2. 8.9.x core/modules/jsonapi/src/Controller/EntityResource.php \Drupal\jsonapi\Controller\EntityResource::getJsonApiParams()
  3. 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 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.