BigPipeRenderStrategy.php in Render cache 7.2
File
modules/renderer/render_cache_big_pipe/src/RenderCache/RenderStrategy/BigPipeRenderStrategy.php
View source
<?php
namespace Drupal\render_cache_big_pipe\RenderCache\RenderStrategy;
use Drupal\render_cache\RenderCache\RenderStrategy\BaseRenderStrategy;
class BigPipeRenderStrategy extends BaseRenderStrategy {
protected static $placeholders = array();
public static function getPlaceholders() {
return static::$placeholders;
}
public function render(array $args) {
$placeholders = array();
foreach ($args as $placeholder => $ph_object) {
$placeholders[$placeholder] = array();
$id = drupal_html_id('render-cache-big-pipe-' . $ph_object['type'] . '-' . $ph_object['id']);
$placeholders[$placeholder]['#markup'] = '<div id="' . $id . '"></div>';
static::$placeholders[$id] = $ph_object;
}
return $placeholders;
}
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);
$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;
}
}