class BigPipeRenderStrategy in Render cache 7.2
Big Pipe RenderStrategy - Provides big pipe processing for placeholders.
Hierarchy
- class \Drupal\render_cache\RenderCache\RenderStrategy\BaseRenderStrategy extends \Drupal\Component\Plugin\PluginBase implements RenderStrategyInterface
- class \Drupal\render_cache_big_pipe\RenderCache\RenderStrategy\BigPipeRenderStrategy
Expanded class hierarchy of BigPipeRenderStrategy
1 file declares its use of BigPipeRenderStrategy
- render_cache_big_pipe.module in modules/
renderer/ render_cache_big_pipe/ render_cache_big_pipe.module - Hook implementations and frequently used functions for render cache big pipe module.
File
- modules/
renderer/ render_cache_big_pipe/ src/ RenderCache/ RenderStrategy/ BigPipeRenderStrategy.php, line 16 - Contains \Drupal\render_cache_big_pipe\RenderCache\RenderStrategy\BigPipeRenderStrategy
Namespace
Drupal\render_cache_big_pipe\RenderCache\RenderStrategyView source
class BigPipeRenderStrategy extends BaseRenderStrategy {
protected static $placeholders = array();
public static function getPlaceholders() {
return static::$placeholders;
}
/**
* {@inheritdoc}
*/
public function render(array $args) {
$placeholders = array();
foreach ($args as $placeholder => $ph_object) {
// @todo Replace with a nice loading theme.
$placeholders[$placeholder] = array();
$id = drupal_html_id('render-cache-big-pipe-' . $ph_object['type'] . '-' . $ph_object['id']);
$placeholders[$placeholder]['#markup'] = '<div id="' . $id . '"></div>';
// Store the data for later usage.
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);
// @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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BigPipeRenderStrategy:: |
protected static | property | ||
BigPipeRenderStrategy:: |
public static | function | ||
BigPipeRenderStrategy:: |
public | function |
Overrides RenderStrategyInterface:: |
|
BigPipeRenderStrategy:: |
public | function |