BigPipeStrategy::generateBigPipePlaceholderId

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

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.

File

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

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'])) {
    $callback = $placeholder_render_array['#lazy_builder'][0];
    $arguments = $placeholder_render_array['#lazy_builder'][1];
    $token = hash('crc32b', serialize($placeholder_render_array));
    return UrlHelper::buildQuery(['callback' => $callback, 'args' => $arguments, 'token' => $token]);
  }
  // When the placeholder's render array is not using a #lazy_builder,
  // anything could be in there: only #lazy_builder has a strict contract that
  // allows us to create a more sane selector. Therefore, simply the original
  // placeholder into a usable placeholder ID, at the cost of it being obtuse.
  else {
    return Html::getId($original_placeholder);
  }
}
doc_Drupal
2016-10-29 08:46:20
Comments
Leave a Comment

Please login to continue.