tablesort_get_sort($headers)
Determines the current sort direction.
$headers: An array of column headers in the format described in '#type' => 'table'.
The current sort direction ("asc" or "desc").
function tablesort_get_sort($headers) { $query = \Drupal::request()->query; if ($query->has('sort')) { return (strtolower($query->get('sort')) == 'desc') ? 'desc' : 'asc'; } // The user has not specified a sort. Use the default for the currently sorted // header if specified; otherwise use "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'; }
© 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!includes!tablesort.inc/function/tablesort_get_sort/8.1.x