diff --git a/core/includes/tablesort.inc b/core/includes/tablesort.inc index 53e5fe3..b42ae26 100644 --- a/core/includes/tablesort.inc +++ b/core/includes/tablesort.inc @@ -111,8 +111,9 @@ function tablesort_get_query_parameters() { * * @return * An associative array describing the criterion, containing the keys: - * - "name": The localized title of the table column. - * - "sql": The name of the database field to sort on. + * - "field": The name of the field to sort on. + * - "query_field": The name of the database field to sort on. + * - "query_reverse": TRUE for normal sorting, FALSE for reverse sorting. */ function tablesort_get_order($headers) { $order = isset($_GET['order']) ? $_GET['order'] : ''; diff --git a/core/lib/Drupal/Core/Entity/Query/QueryBase.php b/core/lib/Drupal/Core/Entity/Query/QueryBase.php index 394f91a..b7144f3 100644 --- a/core/lib/Drupal/Core/Entity/Query/QueryBase.php +++ b/core/lib/Drupal/Core/Entity/Query/QueryBase.php @@ -261,12 +261,6 @@ protected function initializePager() { * Implements \Drupal\Core\Entity\Query\QueryInterface::tableSort(). */ 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'] = ''; - } - } $ts = tablesort_get_order($headers); $direction = tablesort_get_sort($headers); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php index e34f61b..f10195c 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAdminTest.php @@ -66,7 +66,7 @@ function testContentAdminSort() { ->fetchCol(); $nodes_form = array(); - $this->drupalGet('admin/content', array('query' => array('sort' => 'asc', 'order' => 'Title'))); + $this->drupalGet('admin/content', array('query' => array('sort' => 'asc', 'order' => 'n.title'))); foreach ($this->xpath('//table/tbody/tr/td/div/input/@value') as $input) { $nodes_form[] = $input; } diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php index c7cc2a9..7e093cf 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/TableSortExtenderUnitTest.php @@ -55,8 +55,9 @@ function testTableSortInit() { // up in $ts['query']. $_GET = array(); $expected_ts = array( - 'name' => 'foo', - 'sql' => '', + 'field' => NULL, + 'query_field' => NULL, + 'query_reverse' => false, 'sort' => 'asc', 'query' => array(), ); @@ -113,9 +114,10 @@ function testTableSortInit() { ); $ts = tablesort_init($headers); $expected_ts = array( - 'name' => '2', - 'sql' => 'two', - 'sort' => 'desc', + 'field' => 'one', + 'query_field' => 'one', + 'query_reverse' => false, + 'sort' => 'asc', 'query' => array(), ); $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); @@ -131,8 +133,9 @@ function testTableSortInit() { ); $ts = tablesort_init($headers); $expected_ts = array( - 'name' => '1', - 'sql' => 'one', + 'field' => 'one', + 'query_field' => 'one', + 'query_reverse' => false, 'sort' => 'asc', 'query' => array(), ); @@ -151,10 +154,13 @@ function testTableSortInit() { 'alpha' => 'beta', ); $expected_ts = array( - 'name' => '1', - 'sql' => 'one', + 'field' => 'one', + 'query_field' => 'one', + 'query_reverse' => false, 'sort' => 'asc', - 'query' => array('alpha' => 'beta'), + 'query' => array( + 'alpha' => 'beta', + ), ); $ts = tablesort_init($headers); $this->verbose(strtr('$ts:
!ts', array('!ts' => check_plain(var_export($ts, TRUE))))); diff --git a/core/modules/system/lib/Drupal/system/Tests/Database/SelectTableSortDefaultTest.php b/core/modules/system/lib/Drupal/system/Tests/Database/SelectTableSortDefaultTest.php index 200a82a..62a6577 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Database/SelectTableSortDefaultTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Database/SelectTableSortDefaultTest.php @@ -28,10 +28,10 @@ public static function getInfo() { */ function testTableSortQuery() { $sorts = array( - array('field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'), - array('field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'), - array('field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'), - array('field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'), + array('field' => 'tid', 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'), + array('field' => 'tid', 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'), + array('field' => 'task', 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'), + array('field' => 'task', 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'), // more elements here ); @@ -56,10 +56,10 @@ function testTableSortQuery() { */ function testTableSortQueryFirst() { $sorts = array( - array('field' => t('Task ID'), 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'), - array('field' => t('Task ID'), 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'), - array('field' => t('Task'), 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'), - array('field' => t('Task'), 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'), + array('field' => 'tid', 'sort' => 'desc', 'first' => 'perform at superbowl', 'last' => 'eat'), + array('field' => 'tid', 'sort' => 'asc', 'first' => 'eat', 'last' => 'perform at superbowl'), + array('field' => 'task', 'sort' => 'asc', 'first' => 'code', 'last' => 'sleep'), + array('field' => 'task', 'sort' => 'desc', 'first' => 'sleep', 'last' => 'code'), // more elements here ); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index f42ea78..caed147 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -355,10 +355,10 @@ protected function testTableSort() { // assert that all entities from one bundle are after the other as the // order dictates. $_GET['sort'] = 'asc'; - $_GET['order'] = 'Type'; + $_GET['order'] = 'type'; $header = array( - 'id' => array('data' => 'Id', 'specifier' => 'ftid'), - 'type' => array('data' => 'Type', 'specifier' => 'fttype'), + 'id' => array('field' => 'id', 'specifier' => 'ftid'), + 'type' => array('field' => 'type', 'specifier' => 'fttype'), ); $this->queryResults = array_values($this->factory->get('test_entity') @@ -367,15 +367,15 @@ protected function testTableSort() { $this->assertBundleOrder('asc'); $_GET['sort'] = 'desc'; $header = array( - 'id' => array('data' => 'Id', 'specifier' => 'ftid'), - 'type' => array('data' => 'Type', 'specifier' => 'fttype'), + 'id' => array('field' => 'id', 'specifier' => 'ftid'), + 'type' => array('field' => 'type', 'specifier' => 'fttype'), ); $this->queryResults = array_values($this->factory->get('test_entity') ->tableSort($header) ->execute()); $this->assertBundleOrder('desc'); // Ordering on ID is definite, however. - $_GET['order'] = 'Id'; + $_GET['order'] = 'id'; $this->queryResults = $this->factory->get('test_entity') ->tableSort($header) ->execute();