BigPipeStrategy::createBigPipeJsPlaceholder

protected static BigPipeStrategy::createBigPipeJsPlaceholder($original_placeholder, array $placeholder_render_array)

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.

File

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

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' => '<div data-big-pipe-placeholder-id="' . Html::escape($big_pipe_placeholder_id) . '"></div>',
    '#cache' => [
      'max-age' => 0,
      'contexts' => [
        'session.exists',
      ],
    ],
    '#attached' => [
      'library' => [
        'big_pipe/big_pipe',
      ],
      // Inform BigPipe' JavaScript known BigPipe placeholder IDs (a whitelist).
      'drupalSettings' => [
        'bigPipePlaceholderIds' => [$big_pipe_placeholder_id => TRUE],
      ],
      'big_pipe_placeholders' => [
        Html::escape($big_pipe_placeholder_id) => $placeholder_render_array,
      ],
    ],
  ];
}
doc_Drupal
2016-10-29 08:46:19
Comments
Leave a Comment

Please login to continue.