public function PlaceholderGenerator::createPlaceholder in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Render/PlaceholderGenerator.php \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder()
- 9 core/lib/Drupal/Core/Render/PlaceholderGenerator.php \Drupal\Core\Render\PlaceholderGenerator::createPlaceholder()
File
- core/lib/Drupal/Core/Render/PlaceholderGenerator.php, line 69
Class
- PlaceholderGenerator
- Turns a render array into a placeholder.
Namespace
Drupal\Core\Render
Code
public function createPlaceholder(array $element) {
$placeholder_render_array = array_intersect_key($element, [
'#lazy_builder' => TRUE,
'#cache' => TRUE,
]);
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 = UrlHelper::buildQuery($placeholder_render_array['#lazy_builder'][1]);
$token = Crypt::hashBase64(serialize($placeholder_render_array));
$placeholder_markup = '<drupal-render-placeholder callback="' . Html::escape($callback) . '" arguments="' . Html::escape($arguments) . '" token="' . Html::escape($token) . '"></drupal-render-placeholder>';
$placeholder_element = [];
$placeholder_element['#markup'] = Markup::create($placeholder_markup);
$placeholder_element['#attached']['placeholders'][$placeholder_markup] = $placeholder_render_array;
return $placeholder_element;
}