You are here

public function JsonApiParamEnhancer::enhance in JSON:API 8

File

src/Routing/JsonApiParamEnhancer.php, line 60

Class

JsonApiParamEnhancer
Processes the request query parameters.

Namespace

Drupal\jsonapi\Routing

Code

public function enhance(array $defaults, Request $request) {
  $options = [];
  $resource_type = Routes::getResourceTypeNameFromParameters($defaults);
  $context = [
    'entity_type_id' => $resource_type
      ->getEntityTypeId(),
    'bundle' => $resource_type
      ->getBundle(),
  ];
  if ($request->query
    ->has('sort')) {
    $sort = $request->query
      ->get('sort');
    $options['sort'] = $this->sortNormalizer
      ->denormalize($sort, Sort::class, NULL, $context);
  }
  $page = $request->query
    ->has('page') ? $request->query
    ->get('page') : [];
  $options['page'] = $this->pageNormalizer
    ->denormalize($page, OffsetPage::class);
  $defaults['_json_api_params'] = $options;
  return $defaults;
}