You are here

protected function DataProvider::parseRequestForListSort in RESTful 7.2

Parses the request to get the sorting options.

Return value

array With the different sorting options.

Throws

\Drupal\restful\Exception\BadRequestException

\Drupal\restful\Exception\UnprocessableEntityException

4 calls to DataProvider::parseRequestForListSort()
DataProviderDbQuery::queryForListSort in src/Plugin/resource/DataProvider/DataProviderDbQuery.php
Sort the query for list.
DataProviderEntity::queryForListSort in src/Plugin/resource/DataProvider/DataProviderEntity.php
Sort the query for list.
DataProviderPlug::applySort in src/Plugin/resource/DataProvider/DataProviderPlug.php
Sorts plugins on the list based on the request options.
DataProviderVariable::applySort in modules/restful_example/src/Plugin/resource/variables/DataProviderVariable.php
Sorts plugins on the list based on the request options.

File

src/Plugin/resource/DataProvider/DataProvider.php, line 340
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProvider.

Class

DataProvider

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

protected function parseRequestForListSort() {
  $input = $this
    ->getRequest()
    ->getParsedInput();
  if (empty($input['sort'])) {
    return array();
  }
  $url_params = $this->options['urlParams'];
  if (!$url_params['sort']) {
    throw new UnprocessableEntityException('Sort parameters have been disabled in server configuration.');
  }
  $sorts = array();
  foreach (explode(',', $input['sort']) as $sort) {
    $direction = $sort[0] == '-' ? 'DESC' : 'ASC';
    $sort = str_replace('-', '', $sort);

    // Check the sort is on a legal key.
    if (!$this->fieldDefinitions
      ->get($sort)) {
      throw new BadRequestException(format_string('The sort @sort is not allowed for this path.', array(
        '@sort' => $sort,
      )));
    }
    $sorts[$sort] = $direction;
  }
  return $sorts;
}