class Sort (View source)

internal  JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
 

Gathers information about the sort parameter.

Constants

KEY_NAME

The JSON:API sort key name.

PATH_KEY

The field key in the sort parameter: sort[lorem][].

DIRECTION_KEY

The direction key in the sort parameter: sort[lorem][].

LANGUAGE_KEY

The langcode key in the sort parameter: sort[lorem][].

Properties

protected string $fields

The fields on which to sort.

Methods

__construct(array $fields)

Constructs a new Sort object.

fields()

Gets the root condition group.

static Sort
createFromQueryParameter(mixed $parameter)

Creates a Sort object from a query parameter.

static array
expandFieldString(string $fields)

Expands a simple string sort into a more expressive sort that we can use.

static array
expandItem(array $sort_item)

Expands a sort item in case a shortcut was used.

Details

__construct(array $fields)

Constructs a new Sort object.

Takes an array of sort fields. Example: [ [ 'path' => 'changed', 'direction' => 'DESC', ], [ 'path' => 'title', 'direction' => 'ASC', 'langcode' => 'en-US', ], ]

Parameters

array $fields

The entity query sort fields.

fields()

Gets the root condition group.

static Sort createFromQueryParameter(mixed $parameter)

Creates a Sort object from a query parameter.

Parameters

mixed $parameter

The sort query parameter from the Symfony request object.

Return Value

Sort

A Sort object with defaults.

static protected array expandFieldString(string $fields)

Expands a simple string sort into a more expressive sort that we can use.

Parameters

string $fields

The comma separated list of fields to expand into an array.

Return Value

array

The expanded sort.

static protected array expandItem(array $sort_item)

Expands a sort item in case a shortcut was used.

Parameters

array $sort_item

The raw sort item.

Return Value

array

The expanded sort item.