function StatusMessages::generatePlaceholder

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/Element/StatusMessages.php \Drupal\Core\Render\Element\StatusMessages::generatePlaceholder()
  2. 10 core/lib/Drupal/Core/Render/Element/StatusMessages.php \Drupal\Core\Render\Element\StatusMessages::generatePlaceholder()
  3. 11.x core/lib/Drupal/Core/Render/Element/StatusMessages.php \Drupal\Core\Render\Element\StatusMessages::generatePlaceholder()

#pre_render callback to generate a placeholder.

Parameters

array $element: A renderable array.

Return value

array The updated renderable array containing the placeholder.

File

core/lib/Drupal/Core/Render/Element/StatusMessages.php, line 48

Class

StatusMessages
Provides a messages element.

Namespace

Drupal\Core\Render\Element

Code

public static function generatePlaceholder(array $element) {
    $build = [
        '#lazy_builder' => [
            get_class() . '::renderMessages',
            [
                $element['#display'],
            ],
        ],
        '#create_placeholder' => TRUE,
    ];
    // Directly create a placeholder as we need this to be placeholdered
    // regardless if this is a POST or GET request.
    // @todo remove this when https://www.drupal.org/node/2367555 lands.
    $build = \Drupal::service('render_placeholder_generator')->createPlaceholder($build);
    if ($element['#include_fallback']) {
        return [
            'fallback' => [
                '#markup' => '<div data-drupal-messages-fallback class="hidden"></div>',
            ],
            'messages' => $build,
        ];
    }
    return $build;
}

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