You are here

protected function PagerTestController::buildTestTable in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php \Drupal\pager_test\Controller\PagerTestController::buildTestTable()

Builds a render array for a pageable test table.

Parameters

int $element: The pager element to be used for paging.

int $limit: The limit of rows per page for the specified element.

Return value

array A render array.

2 calls to PagerTestController::buildTestTable()
PagerTestController::multiplePagers in core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
Returns a page with multiple pagers.
PagerTestController::queryParameters in core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php
Returns a pager with 'parameters' variable.

File

core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php, line 52

Class

PagerTestController
Controller routine for testing the pager.

Namespace

Drupal\pager_test\Controller

Code

protected function buildTestTable($element, $limit) {
  $header = [
    [
      'data' => 'wid',
    ],
    [
      'data' => 'type',
    ],
    [
      'data' => 'timestamp',
    ],
  ];
  $query = Database::getConnection()
    ->select('watchdog', 'd')
    ->extend(PagerSelectExtender::class)
    ->element($element);
  $result = $query
    ->fields('d', [
    'wid',
    'type',
    'timestamp',
  ])
    ->limit($limit)
    ->orderBy('d.wid')
    ->execute();
  $rows = [];
  foreach ($result as $row) {
    $rows[] = [
      'data' => (array) $row,
    ];
  }
  return [
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t("There are no watchdog records found in the db"),
  ];
}