You are here

public static function StatusMessages::generatePlaceholder in Drupal 8

Same name and namespace in other branches
  1. 9 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;
}