protected function RestfulDataProviderEFQ::queryForListSort in RESTful 7
Sort the query for list.
Parameters
\EntityFieldQuery $query: The query object.
Throws
See also
\RestfulEntityBase::getQueryForList
1 call to RestfulDataProviderEFQ::queryForListSort()
- RestfulDataProviderEFQ::getQueryForList in plugins/
restful/ RestfulDataProviderEFQ.php - Prepare a query for RestfulEntityBase::getList().
File
- plugins/
restful/ RestfulDataProviderEFQ.php, line 133 - Contains \RestfulDataProviderEFQ
Class
- RestfulDataProviderEFQ
- @file Contains \RestfulDataProviderEFQ
Code
protected function queryForListSort(\EntityFieldQuery $query) {
$public_fields = $this
->getPublicFields();
// Get the sorting options from the request object.
$sorts = $this
->parseRequestForListSort();
$sorts = $sorts ? $sorts : $this
->defaultSortInfo();
foreach ($sorts as $public_field_name => $direction) {
// Determine if sorting is by field or property.
if (!($property_name = $public_fields[$public_field_name]['property'])) {
throw new \RestfulBadRequestException('The current sort selection does not map to any entity property or Field API field.');
}
if (field_info_field($property_name)) {
$query
->fieldOrderBy($public_fields[$public_field_name]['property'], $public_fields[$public_field_name]['column'], $direction);
}
else {
$column = $this
->getColumnFromProperty($property_name);
$query
->propertyOrderBy($column, $direction);
}
}
}