You are here

public function DatabaseTestController::testTablesort in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php \Drupal\database_test\Controller\DatabaseTestController::testTablesort()

Runs a tablesort query 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::testTablesort'
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 94
Contains \Drupal\database_test\Controller\DatabaseTestController.

Class

DatabaseTestController
Controller routines for database_test routes.

Namespace

Drupal\database_test\Controller

Code

public function testTablesort() {
  $header = array(
    'tid' => array(
      'data' => t('Task ID'),
      'field' => 'tid',
      'sort' => 'desc',
    ),
    'pid' => array(
      'data' => t('Person ID'),
      'field' => 'pid',
    ),
    'task' => array(
      'data' => t('Task'),
      'field' => 'task',
    ),
    'priority' => array(
      'data' => t('Priority'),
      'field' => 'priority',
    ),
  );
  $query = db_select('test_task', 't');
  $query
    ->fields('t', array(
    'tid',
    'pid',
    'task',
    'priority',
  ));
  $query = $query
    ->extend('Drupal\\Core\\Database\\Query\\TableSortExtender')
    ->orderByHeader($header);

  // We need all the results at once to check the sort.
  $tasks = $query
    ->execute()
    ->fetchAll();
  return new JsonResponse(array(
    'tasks' => $tasks,
  ));
}