function RendererPlaceholdersTest::generatePlaceholderElement

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::generatePlaceholderElement()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php \Drupal\Tests\Core\Render\RendererPlaceholdersTest::generatePlaceholderElement()
  3. 11.x 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

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,
    ];
}

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