You are here

public function QueryBase::tableSort in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Query/QueryBase.php \Drupal\Core\Entity\Query\QueryBase::tableSort()

Enables sortable tables for this query.

Parameters

$headers: An array of headers of the same structure as described in template_preprocess_table(). Use a 'specifier' in place of a 'field' to specify what to sort on. This can be an entity or a field as described in condition().

Return value

\Drupal\Core\Entity\Query\QueryInterface The called object.

Overrides QueryInterface::tableSort

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 311
Contains \Drupal\Core\Entity\Query\QueryBase.

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

public function tableSort(&$headers) {

  // If 'field' is not initialized, the header columns aren't clickable.
  foreach ($headers as $key => $header) {
    if (is_array($header) && isset($header['specifier'])) {
      $headers[$key]['field'] = '';
    }
  }
  $order = tablesort_get_order($headers);
  $direction = tablesort_get_sort($headers);
  foreach ($headers as $header) {
    if (is_array($header) && $header['data'] == $order['name']) {
      $this
        ->sort($header['specifier'], $direction, isset($header['langcode']) ? $header['langcode'] : NULL);
    }
  }
  return $this;
}