public function PageBlockDisplayVariant::buildBlock in Page Manager 8
Same name and namespace in other branches
- 8.4 src/Plugin/DisplayVariant/PageBlockDisplayVariant.php \Drupal\page_manager\Plugin\DisplayVariant\PageBlockDisplayVariant::buildBlock()
#pre_render callback for building a block.
Renders the content using the provided block plugin, if there is no content, aborts rendering, and makes sure the block won't be rendered.
File
- src/
Plugin/ DisplayVariant/ PageBlockDisplayVariant.php, line 183 - Contains \Drupal\page_manager\Plugin\DisplayVariant\PageBlockDisplayVariant.
Class
- PageBlockDisplayVariant
- Provides a variant plugin that simply contains blocks.
Namespace
Drupal\page_manager\Plugin\DisplayVariantCode
public function buildBlock($build) {
$content = $build['#block_plugin']
->build();
// Remove the block plugin from the render array.
unset($build['#block_plugin']);
if ($content !== NULL && !Element::isEmpty($content)) {
$build['content'] = $content;
}
else {
// Abort rendering: render as the empty string and ensure this block is
// render cached, so we can avoid the work of having to repeatedly
// determine whether the block is empty. E.g. modifying or adding entities
// could cause the block to no longer be empty.
$build = [
'#markup' => '',
'#cache' => $build['#cache'],
];
}
// If $content is not empty, then it contains cacheability metadata, and
// we must merge it with the existing cacheability metadata. This allows
// blocks to be empty, yet still bubble cacheability metadata, to indicate
// why they are empty.
if (!empty($content)) {
CacheableMetadata::createFromRenderArray($build)
->merge(CacheableMetadata::createFromRenderArray($content))
->applyTo($build);
}
return $build;
}