You are here

protected function DataProviderEntity::alterSortQuery in RESTful 7.2

Placeholder method to alter the filters.

If no further processing for the filter is needed (i.e. alterFilterQuery already added the query filters to $query), then set the 'processed' flag in $filter to TRUE. Otherwise normal filtering will be added on top, leading to unexpected results.

Parameters

array $sort: The sort array containing the keys:

  • public_field: Contains the public property.
  • direction: The sorting direction, either ASC or DESC.
  • resource_id: The resource machine name.

\EntityFieldQuery $query: The EFQ to add the filter to.

Return value

array The modified $sort array.

1 call to DataProviderEntity::alterSortQuery()
DataProviderEntity::queryForListSort in src/Plugin/resource/DataProvider/DataProviderEntity.php
Sort the query for list.

File

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

Class

DataProviderEntity
Class DataProviderEntity.

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

protected function alterSortQuery(array $sort, \EntityFieldQuery $query) {
  if (!($resource_field = $this->fieldDefinitions
    ->get($sort['public_field']))) {
    return $sort;
  }
  if (!$resource_field instanceof ResourceFieldEntityAlterableInterface) {

    // Check if the resource can check on decorated instances.
    if (!$resource_field instanceof ExplorableDecoratorInterface || !$resource_field
      ->isInstanceOf(ResourceFieldEntityAlterableInterface::class)) {
      return $sort;
    }
  }
  return $resource_field
    ->alterSortEntityFieldQuery($sort, $query);
}