function DatabaseTestController::testTablesortFirst
Same name in other branches
- 9 core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php \Drupal\database_test\Controller\DatabaseTestController::testTablesortFirst()
- 10 core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php \Drupal\database_test\Controller\DatabaseTestController::testTablesortFirst()
- 11.x core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php \Drupal\database_test\Controller\DatabaseTestController::testTablesortFirst()
Runs a tablesort query with a second order_by after and returns the results.
This function does care about the page GET parameter, as set by the simpletest HTTP call.
Return value
\Symfony\Component\HttpFoundation\JsonResponse
1 string reference to 'DatabaseTestController::testTablesortFirst'
- database_test.routing.yml in core/
modules/ system/ tests/ modules/ database_test/ database_test.routing.yml - core/modules/system/tests/modules/database_test/database_test.routing.yml
File
-
core/
modules/ system/ tests/ modules/ database_test/ src/ Controller/ DatabaseTestController.php, line 150
Class
- DatabaseTestController
- Controller routines for database_test routes.
Namespace
Drupal\database_test\ControllerCode
public function testTablesortFirst() {
$header = [
'tid' => [
'data' => t('Task ID'),
'field' => 'tid',
'sort' => 'desc',
],
'pid' => [
'data' => t('Person ID'),
'field' => 'pid',
],
'task' => [
'data' => t('Task'),
'field' => 'task',
],
'priority' => [
'data' => t('Priority'),
'field' => 'priority',
],
];
$query = $this->connection
->select('test_task', 't');
$query->fields('t', [
'tid',
'pid',
'task',
'priority',
]);
$query = $query->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')
->orderByHeader($header)
->orderBy('priority');
// We need all the results at once to check the sort.
$tasks = $query->execute()
->fetchAll();
return new JsonResponse([
'tasks' => $tasks,
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.