public function BlocksRendererHelper::getRenderFromBlockPlugin in Gutenberg 8.2
Same name and namespace in other branches
- 8 src/BlocksRendererHelper.php \Drupal\gutenberg\BlocksRendererHelper::getRenderFromBlockPlugin()
Return render array for given block plugin.
Parameters
\Drupal\Core\Block\BlockPluginInterface $plugin_block: Block Plugin instance.
bool $render_markup: Render the response as markup.
Return value
array|\Drupal\Component\Render\MarkupInterface Array containing render array, or empty.
File
- src/
BlocksRendererHelper.php, line 156
Class
- BlocksRendererHelper
- Class BlocksRendererHelper.
Namespace
Drupal\gutenbergCode
public function getRenderFromBlockPlugin(BlockPluginInterface $plugin_block, $render_markup = TRUE) {
$render = [
'#theme' => 'block',
'#attributes' => [],
'#contextual_links' => [],
'#configuration' => $plugin_block
->getConfiguration(),
'#plugin_id' => $plugin_block
->getPluginId(),
'#base_plugin_id' => $plugin_block
->getBaseId(),
'#derivative_plugin_id' => $plugin_block
->getDerivativeId(),
];
// Handle title blocks specially.
$is_title_block = $plugin_block instanceof TitleBlockPluginInterface;
if ($is_title_block) {
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
$title = $this->titleResolver
->getTitle($request, $route_match
->getRouteObject());
$plugin_block
->setTitle($title);
}
// Build the block content.
$content = $plugin_block
->build();
$this
->addPropertiesToRender($render, $content);
$this
->addCacheTagsToRender($render, $content);
$render['content'] = $content;
if ($is_title_block) {
// Add the title block cache context.
$build['content']['#cache']['contexts'][] = 'url';
}
if ($render_markup) {
return $this->renderer
->renderRoot($render);
}
return $render;
}