public static function Sort::createFromQueryParameter in JSON:API 8.2
Creates a Sort object from a query parameter.
Parameters
mixed $parameter: The `sort` query parameter from the Symfony request object.
Return value
self A Sort object with defaults.
3 calls to Sort::createFromQueryParameter()
- EntityResource::getJsonApiParams in src/
Controller/ EntityResource.php - Extracts JSON:API query parameters from the request.
- SortTest::testCreateFromQueryParameter in tests/
src/ Unit/ Query/ SortTest.php - @covers ::createFromQueryParameter @dataProvider parameterProvider
- SortTest::testCreateFromQueryParameterFail in tests/
src/ Unit/ Query/ SortTest.php - @covers ::createFromQueryParameter @dataProvider badParameterProvider
File
- src/
Query/ Sort.php, line 93
Class
- Sort
- Gathers information about the sort parameter.
Namespace
Drupal\jsonapi\QueryCode
public static function createFromQueryParameter($parameter) {
if (empty($parameter)) {
$cacheability = (new CacheableMetadata())
->addCacheContexts([
'url.query_args:sort',
]);
throw new CacheableBadRequestHttpException($cacheability, 'You need to provide a value for the sort parameter.');
}
// Expand a JSON:API compliant sort into a more expressive sort parameter.
if (is_string($parameter)) {
$parameter = static::expandFieldString($parameter);
}
// Expand any defaults into the sort array.
$expanded = [];
foreach ($parameter as $sort_index => $sort_item) {
$expanded[$sort_index] = static::expandItem($sort_item);
}
return new static($expanded);
}