protected static BlockViewBuilder::buildPreRenderableBlock($entity, ModuleHandlerInterface $module_handler)
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.
File
- core/modules/block/src/BlockViewBuilder.php, line 134
Class
- BlockViewBuilder
- Provides a Block view builder.
Namespace
Drupal\block
Code
protected static function buildPreRenderableBlock($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; }
Please login to continue.