function BigPipeStrategy::generateBigPipePlaceholderId

Same name in other branches
  1. 9 core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy::generateBigPipePlaceholderId()
  2. 8.9.x core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy::generateBigPipePlaceholderId()
  3. 11.x core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php \Drupal\big_pipe\Render\Placeholder\BigPipeStrategy::generateBigPipePlaceholderId()

Generates a BigPipe placeholder ID.

Parameters

string $original_placeholder: The original placeholder.

array $placeholder_render_array: The render array for a placeholder.

Return value

string The generated BigPipe placeholder ID.

2 calls to BigPipeStrategy::generateBigPipePlaceholderId()
BigPipeStrategy::createBigPipeJsPlaceholder in core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php
Creates a BigPipe JS placeholder.
BigPipeStrategy::createBigPipeNoJsPlaceholder in core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php
Creates a BigPipe no-JS placeholder.

File

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

Class

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

Namespace

Drupal\big_pipe\Render\Placeholder

Code

protected static function generateBigPipePlaceholderId($original_placeholder, array $placeholder_render_array) {
    // Generate a BigPipe placeholder ID (to be used by BigPipe's JavaScript).
    // @see \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder()
    if (isset($placeholder_render_array['#lazy_builder'])) {
        // Be sure cache contexts and tags are sorted before serializing them and
        // making hash. Issue #3225328 removes sort from contexts and tags arrays
        // for performances reasons.
        if (isset($placeholder_render_array['#cache']['contexts'])) {
            sort($placeholder_render_array['#cache']['contexts']);
        }
        if (isset($placeholder_render_array['#cache']['tags'])) {
            sort($placeholder_render_array['#cache']['tags']);
        }
        $callback = $placeholder_render_array['#lazy_builder'][0];
        $arguments = $placeholder_render_array['#lazy_builder'][1];
        $token = Crypt::hashBase64(serialize($placeholder_render_array));
        return UrlHelper::buildQuery([
            'callback' => $callback,
            'args' => $arguments,
            'token' => $token,
        ]);
    }
    else {
        return Html::getId($original_placeholder);
    }
}

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