class JsonApiParamEnhancer in JSON:API 8
Processes the request query parameters.
@internal
Hierarchy
- class \Drupal\jsonapi\Routing\JsonApiParamEnhancer implements RouteEnhancerInterface
Expanded class hierarchy of JsonApiParamEnhancer
1 file declares its use of JsonApiParamEnhancer
- JsonApiParamEnhancerTest.php in tests/
src/ Unit/ Routing/ JsonApiParamEnhancerTest.php
1 string reference to 'JsonApiParamEnhancer'
1 service uses JsonApiParamEnhancer
File
- src/
Routing/ JsonApiParamEnhancer.php, line 18
Namespace
Drupal\jsonapi\RoutingView source
class JsonApiParamEnhancer implements RouteEnhancerInterface {
/**
* The filter normalizer.
*
* @var \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
*/
protected $filterNormalizer;
/**
* The sort normalizer.
*
* @var \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
*/
protected $sortNormalizer;
/**
* The page normalizer.
*
* @var Symfony\Component\Serializer\Normalizer\DenormalizerInterface
*/
protected $pageNormalizer;
/**
* {@inheritdoc}
*/
public function __construct(DenormalizerInterface $filter_normalizer, DenormalizerInterface $sort_normalizer, DenormalizerInterface $page_normalizer) {
$this->filterNormalizer = $filter_normalizer;
$this->sortNormalizer = $sort_normalizer;
$this->pageNormalizer = $page_normalizer;
}
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return (bool) Routes::getResourceTypeNameFromParameters($route
->getDefaults());
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonApiParamEnhancer:: |
protected | property | The filter normalizer. | |
JsonApiParamEnhancer:: |
protected | property | The page normalizer. | |
JsonApiParamEnhancer:: |
protected | property | The sort normalizer. | |
JsonApiParamEnhancer:: |
public | function |
Declares if the route enhancer applies to the given route. Overrides RouteEnhancerInterface:: |
|
JsonApiParamEnhancer:: |
public | function | Update the defaults based on its own data and the request. | |
JsonApiParamEnhancer:: |
public | function |