core/lib/Drupal/Core/Block/StatefulBlockPluginInterface.php | 8 ++++++++ core/modules/block/src/BlockViewBuilder.php | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/lib/Drupal/Core/Block/StatefulBlockPluginInterface.php b/core/lib/Drupal/Core/Block/StatefulBlockPluginInterface.php index d52ea18..83c28c6 100644 --- a/core/lib/Drupal/Core/Block/StatefulBlockPluginInterface.php +++ b/core/lib/Drupal/Core/Block/StatefulBlockPluginInterface.php @@ -10,6 +10,14 @@ /** * The interface for blocks that carry state and can hence not be lazily built. * + * Some block plugins are stateful (they carry data in their internal properties + * and hence are stateful) and can therefore not be lazily rendered. + * + * For example: the main content block plugin, which gets the main content + * injected. If it was lazily rendered, we would not have a way to get the + * main content block plugin instance that got the main content injected. Thus + * the state would be lost and it would not be able to render correctly. + * * @see \Drupal\Core\Block\MainContentBlockPluginInterface * @see \Drupal\views\Plugin\Block\ViewsExposedFilterBlock * diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 1703146..c4f8f50 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -63,15 +63,10 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la ], ); - // Some blocks are stateful (carry properties, hence have state) and can - // therefore not be lazily built (using #lazy_builder callbacks). For - // example: the main content block, which gets the main content injected. - // If they were lazily built, then we would not have any way to recreate - // the original state. if ($plugin instanceof StatefulBlockPluginInterface) { // Immediately build a #pre_render-able block, since this block cannot // be built lazily. - $build[$entity_id] += self::buildPreRenderableBlock($entity, $this->moduleHandler()); + $build[$entity_id] += static::buildPreRenderableBlock($entity, $this->moduleHandler()); } else { // Assign a #lazy_builder callback, which will generate a #pre_render- @@ -151,7 +146,7 @@ protected static function buildPreRenderableBlock($entity, ModuleHandlerInterfac * A render array with a #pre_render callback to render the block. */ public static function lazyBuilder($entity_id, $view_mode, $langcode) { - return self::buildPreRenderableBlock(Block::load($entity_id), \Drupal::service('module_handler')); + return static::buildPreRenderableBlock(Block::load($entity_id), \Drupal::service('module_handler')); } /**