You are here

protected function RestfulDataProviderVariable::applyListSort in RESTful 7

Sort the list of variables.

This data provider does not handle compound sorts; the last sort defined will be the one to take effect.

Parameters

array $variables: An indexed array containing elements that represent each variable, each containing a name and a value.

1 call to RestfulDataProviderVariable::applyListSort()
RestfulDataProviderVariable::getVariablesForList in plugins/restful/RestfulDataProviderVariable.php

File

plugins/restful/RestfulDataProviderVariable.php, line 52
Contains \RestfulDataProviderDbQuery

Class

RestfulDataProviderVariable
@file Contains \RestfulDataProviderDbQuery

Code

protected function applyListSort(array &$variables) {
  $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) {
    if (isset($public_fields[$public_field_name]['property'])) {
      $property_name = $public_fields[$public_field_name]['property'];

      // Only sort by name if it's different than Drupal's default.
      if ($property_name == 'name' && $direction == 'DESC') {
        $variables = array_reverse($variables);
      }
    }
  }
  return $variables;
}