public function BigPipeRenderStrategy::renderPlaceholder in Render cache 7.2
File
- modules/
renderer/ render_cache_big_pipe/ src/ RenderCache/ RenderStrategy/ BigPipeRenderStrategy.php, line 42 - Contains \Drupal\render_cache_big_pipe\RenderCache\RenderStrategy\BigPipeRenderStrategy
Class
- BigPipeRenderStrategy
- Big Pipe RenderStrategy - Provides big pipe processing for placeholders.
Namespace
Drupal\render_cache_big_pipe\RenderCache\RenderStrategyCode
public function renderPlaceholder($placeholder, $ph_object) {
$rcc = render_cache_get_controller($ph_object['type']);
$rcc
->setContext($ph_object['context']);
$objects = array(
$ph_object['id'] => $ph_object['object'],
);
$build = $rcc
->viewPlaceholders($objects);
$output = drupal_render($build);
$html = drupal_json_encode($output);
// @todo Add helper function.
$markup = <<<EOF
<script type="text/javascript">
var element = document.getElementById("{<span class="php-variable">$placeholder</span>}");
var newElement = document.createElement("span");
newElement.innerHTML = {<span class="php-variable">$html</span>};
var newChild = newElement.firstChild;
element.parentNode.replaceChild(newChild, element);
</script>
EOF;
return $markup;
}