function RenderPlaceholderMessageTestController::build

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php \Drupal\render_placeholder_message_test\RenderPlaceholderMessageTestController::build()
  2. 10 core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php \Drupal\render_placeholder_message_test\RenderPlaceholderMessageTestController::build()
  3. 11.x core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php \Drupal\render_placeholder_message_test\RenderPlaceholderMessageTestController::build()

Return value

array

3 calls to RenderPlaceholderMessageTestController::build()
RenderPlaceholderMessageTestController::messagesPlaceholderFirst in core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php
RenderPlaceholderMessageTestController::messagesPlaceholderLast in core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php
RenderPlaceholderMessageTestController::messagesPlaceholderMiddle in core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php

File

core/modules/system/tests/modules/render_placeholder_message_test/src/RenderPlaceholderMessageTestController.php, line 57

Class

RenderPlaceholderMessageTestController

Namespace

Drupal\render_placeholder_message_test

Code

protected function build(array $placeholder_order) {
    $build = [];
    $build['messages'] = [
        '#type' => 'status_messages',
    ];
    $build['p1'] = [
        '#lazy_builder' => [
            '\\Drupal\\render_placeholder_message_test\\RenderPlaceholderMessageTestController::setAndLogMessage',
            [
                'P1',
            ],
        ],
        '#create_placeholder' => TRUE,
    ];
    $build['p2'] = [
        '#lazy_builder' => [
            '\\Drupal\\render_placeholder_message_test\\RenderPlaceholderMessageTestController::setAndLogMessage',
            [
                'P2',
            ],
        ],
        '#create_placeholder' => TRUE,
    ];
    
    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container
        ->get('renderer');
    $renderer->executeInRenderContext(new RenderContext(), function () use (&$build, $renderer) {
        return $renderer->render($build, FALSE);
    });
    $reordered = [];
    foreach ($placeholder_order as $placeholder) {
        $reordered[$placeholder] = $build['#attached']['placeholders'][$placeholder];
    }
    $build['#attached']['placeholders'] = $reordered;
    return $build;
}

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