function PagerTestController::buildTestTable

Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php \Drupal\pager_test\Controller\PagerTestController::buildTestTable()
  2. 10 core/modules/system/tests/modules/pager_test/src/Controller/PagerTestController.php \Drupal\pager_test\Controller\PagerTestController::buildTestTable()
  3. 11.x 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"),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.