You are here

protected static function BigPipeStrategy::createBigPipeJsPlaceholder in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy::createBigPipeJsPlaceholder()

Creates a BigPipe JS placeholder.

Parameters

string $original_placeholder: The original placeholder.

array $placeholder_render_array: The render array for a placeholder.

Return value

array The resulting BigPipe JS placeholder render array.

1 call to BigPipeStrategy::createBigPipeJsPlaceholder()
BigPipeStrategy::doProcessPlaceholders in core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php
Transforms placeholders to BigPipe placeholders, either no-JS or JS.

File

core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php, line 198

Class

BigPipeStrategy
Defines the BigPipe placeholder strategy, to send HTML in chunks.

Namespace

Drupal\big_pipe\Render\Placeholder

Code

protected static function createBigPipeJsPlaceholder($original_placeholder, array $placeholder_render_array) {
  $big_pipe_placeholder_id = static::generateBigPipePlaceholderId($original_placeholder, $placeholder_render_array);
  return [
    '#markup' => '<span data-big-pipe-placeholder-id="' . Html::escape($big_pipe_placeholder_id) . '"></span>',
    '#cache' => [
      'max-age' => 0,
      'contexts' => [
        'session.exists',
      ],
    ],
    '#attached' => [
      'library' => [
        'big_pipe/big_pipe',
      ],
      // Inform BigPipe' JavaScript known BigPipe placeholder IDs.
      'drupalSettings' => [
        'bigPipePlaceholderIds' => [
          $big_pipe_placeholder_id => TRUE,
        ],
      ],
      'big_pipe_placeholders' => [
        Html::escape($big_pipe_placeholder_id) => $placeholder_render_array,
      ],
    ],
  ];
}