You are here

public static function BigPipeTestController::counter in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php \Drupal\big_pipe_test\BigPipeTestController::counter()

#lazy_builder callback; returns the current count.

Return value

array The render array.

See also

\Drupal\Tests\big_pipe\Functional\BigPipeTest::testBigPipeMultiOccurrencePlaceholders()

File

core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php, line 142

Class

BigPipeTestController

Namespace

Drupal\big_pipe_test

Code

public static function counter() {

  // Lazy builders are not allowed to build their own state like this function
  // does, but in this case we're intentionally doing that for testing
  // purposes: so we can ensure that each lazy builder is only ever called
  // once with the same parameters.
  static $count;
  if (!isset($count)) {
    $count = 0;
  }
  $count++;
  return [
    '#markup' => BigPipeMarkup::create("<p>The count is {$count}.</p>"),
    '#cache' => [
      'max-age' => 0,
    ],
  ];
}