diff --git a/core/modules/block/src/BlockRepository.php b/core/modules/block/src/BlockRepository.php index 0b9afc8..e9a5eb0 100644 --- a/core/modules/block/src/BlockRepository.php +++ b/core/modules/block/src/BlockRepository.php @@ -78,12 +78,6 @@ public function getVisibleBlocksPerRegion(array &$cacheable_metadata = []) { foreach ($this->blockStorage->loadByProperties(array('theme' => $active_theme->getName())) as $block_id => $block) { /** @var \Drupal\block\BlockInterface $block */ - $block_plugin = $block->getPlugin(); - if ($block_plugin instanceof ContextAwarePluginInterface) { - $contexts = $this->contextRepository->getRuntimeContexts(array_values($block_plugin->getContextMapping())); - $this->contextHandler->applyContextMapping($block_plugin, $contexts); - } - $access = $block->access('view', NULL, TRUE); $region = $block->getRegion(); if (!isset($cacheable_metadata[$region])) { diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 6fc5b2f..7972bbc 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -105,8 +105,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la // Allow altering of cacheability metadata or setting #create_placeholder. $this->moduleHandler->alter(['block_build', "block_build_" . $plugin->getBaseId()], $build[$entity_id], $plugin); - if ($plugin instanceof MainContentBlockPluginInterface - || ($plugin instanceof ContextAwarePluginInterface && !empty($plugin->getContextMapping()))) { + if ($plugin instanceof MainContentBlockPluginInterface) { // Immediately build a #pre_render-able block, since this block cannot // be built lazily. $build[$entity_id] += static::buildPreRenderableBlock($entity, $this->moduleHandler()); @@ -141,6 +140,12 @@ protected static function buildPreRenderableBlock($entity, ModuleHandlerInterfac $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 = [