W3cubDocs

/Drupal 8

public function QueryBase::tableSort

public QueryBase::tableSort(&$headers)

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 306

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;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Query!QueryBase.php/function/QueryBase::tableSort/8.1.x