You are here

public function DatabaseTestController::testTablesortFirst 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::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 126
Contains \Drupal\database_test\Controller\DatabaseTestController.

Class

DatabaseTestController
Controller routines for database_test routes.

Namespace

Drupal\database_test\Controller

Code

public function testTablesortFirst() {
  $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)
    ->orderBy('priority');

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