function PlaceholdersTest::callbackPerUser

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\PlaceholdersTest::callbackPerUser()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\PlaceholdersTest::callbackPerUser()
  3. 11.x core/tests/Drupal/Tests/Core/Render/RendererTestBase.php \Drupal\Tests\Core\Render\PlaceholdersTest::callbackPerUser()

#lazy_builder callback; attaches setting, generates markup, user-specific.

Parameters

string $animal: An animal.

Return value

array A renderable array.

File

core/tests/Drupal/Tests/Core/Render/RendererTestBase.php, line 328

Class

PlaceholdersTest

Namespace

Drupal\Tests\Core\Render

Code

public static function callbackPerUser($animal) {
  // As well as adding the user cache context, additionally suspend the
  // current Fiber if there is one.
  if ($fiber = \Fiber::getCurrent()) {
    $fiber->suspend();
  }
  $build = static::callback($animal);
  $build['#cache']['contexts'][] = 'user';
  return $build;
}

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