You are here

protected function RendererPlaceholdersTest::generatePlaceholderElement in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::generatePlaceholderElement()

Generates an element with a placeholder.

Return value

array An array containing:

  • A render array containing a placeholder.
  • The context used for that #lazy_builder callback.

File

core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php, line 537
Contains \Drupal\Tests\Core\Render\RendererPlaceholdersTest.

Class

RendererPlaceholdersTest
@coversDefaultClass \Drupal\Core\Render\Renderer @covers \Drupal\Core\Render\RenderCache @covers \Drupal\Core\Render\PlaceholderingRenderCache @group Render

Namespace

Drupal\Tests\Core\Render

Code

protected function generatePlaceholderElement() {
  $args = [
    $this
      ->randomContextValue(),
  ];
  $test_element = [];
  $test_element['#attached']['drupalSettings']['foo'] = 'bar';
  $test_element['placeholder']['#cache']['keys'] = [
    'placeholder',
    'output',
    'can',
    'be',
    'render',
    'cached',
    'too',
  ];
  $test_element['placeholder']['#cache']['contexts'] = [];
  $test_element['placeholder']['#create_placeholder'] = TRUE;
  $test_element['placeholder']['#lazy_builder'] = [
    'Drupal\\Tests\\Core\\Render\\PlaceholdersTest::callback',
    $args,
  ];
  return [
    $test_element,
    $args,
  ];
}