You are here

public function PagerTestController::queryParameters 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::queryParameters()

Returns a pager with 'parameters' variable.

The 'pager_calls' parameter counts the calls to the pager, subsequent to the initial call.

1 string reference to 'PagerTestController::queryParameters'
pager_test.routing.yml in core/modules/system/tests/modules/pager_test/pager_test.routing.yml
core/modules/system/tests/modules/pager_test/pager_test.routing.yml

File

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

Class

PagerTestController
Controller routine for testing the pager.

Namespace

Drupal\pager_test\Controller

Code

public function queryParameters() {

  // Example query.
  $build['pager_table_0'] = $this
    ->buildTestTable(0, 5);

  // Counter of calls to the current pager.
  $query_params = $this->pagerParams
    ->getQueryParameters();
  $pager_calls = isset($query_params['pager_calls']) ? $query_params['pager_calls'] ? $query_params['pager_calls'] : 0 : 0;
  $build['l_pager_pager_0'] = [
    '#markup' => $this
      ->t('Pager calls: @pager_calls', [
      '@pager_calls' => $pager_calls,
    ]),
  ];

  // Pager.
  $build['pager_pager_0'] = [
    '#type' => 'pager',
    '#element' => 0,
    '#parameters' => [
      'pager_calls' => ++$pager_calls,
    ],
    '#pre_render' => [
      'Drupal\\pager_test\\Controller\\PagerTestController::showPagerCacheContext',
    ],
  ];
  return $build;
}