function BigPipeStrategy::createBigPipeJsPlaceholder

Same name in other branches
  1. 9 core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy::createBigPipeJsPlaceholder()
  2. 8.9.x core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy::createBigPipeJsPlaceholder()
  3. 10 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 202

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);
    $interface_preview = [];
    if (isset($placeholder_render_array['#lazy_builder'])) {
        $interface_preview = [
            '#theme' => 'big_pipe_interface_preview',
            '#callback' => $placeholder_render_array['#lazy_builder'][0],
            '#arguments' => $placeholder_render_array['#lazy_builder'][1],
        ];
        if (isset($placeholder_render_array['#preview'])) {
            $interface_preview['#preview'] = $placeholder_render_array['#preview'];
            unset($placeholder_render_array['#preview']);
        }
    }
    return [
        '#prefix' => '<span data-big-pipe-placeholder-id="' . Html::escape($big_pipe_placeholder_id) . '">',
        'interface_preview' => $interface_preview,
        '#suffix' => '</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,
            ],
        ],
    ];
}

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