You are here

protected function DataProviderDbQuery::queryForListSort in RESTful 7.2

Sort the query for list.

Parameters

\SelectQuery $query: The query object.

Throws

BadRequestException

See also

\RestfulEntityBase::getQueryForList

1 call to DataProviderDbQuery::queryForListSort()
DataProviderDbQuery::getQueryForList in src/Plugin/resource/DataProvider/DataProviderDbQuery.php

File

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

Class

DataProviderDbQuery

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

protected function queryForListSort(\SelectQuery $query) {

  // Get the sorting options from the request object.
  $sorts = $this
    ->parseRequestForListSort();
  $sorts = $sorts ? $sorts : $this
    ->defaultSortInfo();
  foreach ($sorts as $sort => $direction) {

    /* @var ResourceFieldDbColumnInterface $sort_field */
    if ($sort_field = $this->fieldDefinitions
      ->get($sort)) {
      $query
        ->orderBy($sort_field
        ->getColumnForQuery(), $direction);
    }
  }
}