You are here

function tablesort_get_sort in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/includes/tablesort.inc \tablesort_get_sort()

Determines the current sort direction.

Parameters

$headers: An array of column headers in the format described in '#type' => 'table'.

Return value

The current sort direction ("asc" or "desc").

3 calls to tablesort_get_sort()
QueryBase::tableSort in core/lib/Drupal/Core/Entity/Query/QueryBase.php
Enables sortable tables for this query.
TableSortExtender::getSort in core/lib/Drupal/Core/Database/Query/TableSortExtender.php
Determine the current sort direction.
tablesort_init in core/includes/tablesort.inc
Initializes the table sort context.

File

core/includes/tablesort.inc, line 132
Functions to aid in the creation of sortable tables.

Code

function tablesort_get_sort($headers) {
  $query = \Drupal::request()->query;
  if ($query
    ->has('sort')) {
    return strtolower($query
      ->get('sort')) == 'desc' ? 'desc' : 'asc';
  }
  else {

    // Find out which header is currently being sorted.
    $ts = tablesort_get_order($headers);
    foreach ($headers as $header) {
      if (is_array($header) && isset($header['data']) && $header['data'] == $ts['name'] && isset($header['sort'])) {
        return $header['sort'];
      }
    }
  }
  return 'asc';
}