protected static function BlockViewBuilder::buildPreRenderableBlock in Drupal 10
Same name and namespace in other branches
- 8 core/modules/block/src/BlockViewBuilder.php \Drupal\block\BlockViewBuilder::buildPreRenderableBlock()
- 9 core/modules/block/src/BlockViewBuilder.php \Drupal\block\BlockViewBuilder::buildPreRenderableBlock()
Builds a #pre_render-able block render array.
Parameters
\Drupal\block\BlockInterface $entity: A block config entity.
\Drupal\Core\Extension\ModuleHandlerInterface $module_handler: The module handler service.
Return value
array A render array with a #pre_render callback to render the block.
2 calls to BlockViewBuilder::buildPreRenderableBlock()
- BlockViewBuilder::lazyBuilder in core/
modules/ block/ src/ BlockViewBuilder.php - #lazy_builder callback; builds a #pre_render-able block.
- BlockViewBuilder::viewMultiple in core/
modules/ block/ src/ BlockViewBuilder.php - Builds the render array for the provided entities.
File
- core/
modules/ block/ src/ BlockViewBuilder.php, line 95
Class
- BlockViewBuilder
- Provides a Block view builder.
Namespace
Drupal\blockCode
protected static function buildPreRenderableBlock(BlockInterface $entity, ModuleHandlerInterface $module_handler) {
$plugin = $entity
->getPlugin();
$plugin_id = $plugin
->getPluginId();
$base_id = $plugin
->getBaseId();
$derivative_id = $plugin
->getDerivativeId();
$configuration = $plugin
->getConfiguration();
// Inject runtime contexts.
if ($plugin instanceof ContextAwarePluginInterface) {
$contexts = \Drupal::service('context.repository')
->getRuntimeContexts($plugin
->getContextMapping());
\Drupal::service('context.handler')
->applyContextMapping($plugin, $contexts);
}
// Create the render array for the block as a whole.
// @see template_preprocess_block().
$build = [
'#theme' => 'block',
'#attributes' => [],
// All blocks get a "Configure block" contextual link.
'#contextual_links' => [
'block' => [
'route_parameters' => [
'block' => $entity
->id(),
],
],
],
'#weight' => $entity
->getWeight(),
'#configuration' => $configuration,
'#plugin_id' => $plugin_id,
'#base_plugin_id' => $base_id,
'#derivative_plugin_id' => $derivative_id,
'#id' => $entity
->id(),
'#pre_render' => [
static::class . '::preRender',
],
// Add the entity so that it can be used in the #pre_render method.
'#block' => $entity,
];
// If an alter hook wants to modify the block contents, it can append
// another #pre_render hook.
$module_handler
->alter([
'block_view',
"block_view_{$base_id}",
], $build, $plugin);
return $build;
}