function TableSort::getSort
Same name in other branches
- 7.x includes/tablesort.inc \TableSort::getSort()
- 9 core/lib/Drupal/Core/Utility/TableSort.php \Drupal\Core\Utility\TableSort::getSort()
- 8.9.x core/lib/Drupal/Core/Utility/TableSort.php \Drupal\Core\Utility\TableSort::getSort()
- 11.x core/lib/Drupal/Core/Utility/TableSort.php \Drupal\Core\Utility\TableSort::getSort()
Determines the current sort direction.
Parameters
array $headers: An array of column headers in the format described in '#type' => 'table'.
\Symfony\Component\HttpFoundation\Request|null $request: A current request.
Return value
string The current sort direction ("asc" or "desc").
2 calls to TableSort::getSort()
- QueryBase::tableSort in core/
lib/ Drupal/ Core/ Entity/ Query/ QueryBase.php - Enables sortable tables for this query.
- TableSort::getContextFromRequest in core/
lib/ Drupal/ Core/ Utility/ TableSort.php - Initializes the table sort context.
File
-
core/
lib/ Drupal/ Core/ Utility/ TableSort.php, line 145
Class
- TableSort
- Provides a class for table sorting processing and rendering.
Namespace
Drupal\Core\UtilityCode
public static function getSort(array $headers, Request $request) {
$query = $request->query;
if ($query->has('sort')) {
return strtolower($query->get('sort')) == self::DESC ? self::DESC : self::ASC;
}
// The user has not specified a sort. Use the default for the currently
// sorted header if specified; otherwise use "asc".
// Find out which header is currently being sorted.
$order = static::getOrder($headers, $request);
foreach ($headers as $header) {
if (is_array($header) && isset($header['data']) && $header['data'] == $order['name']) {
if (isset($header['sort'])) {
return $header['sort'];
}
if (isset($header['initial_click_sort'])) {
return $header['initial_click_sort'];
}
}
}
return self::ASC;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.