.../src/Plugin/DisplayVariant/BlockPageVariant.php | 7 +++++++ .../system/src/Plugin/Block/SystemMainBlock.php | 23 ---------------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php index 798805e..7b67093 100644 --- a/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php +++ b/core/modules/block/src/Plugin/DisplayVariant/BlockPageVariant.php @@ -142,6 +142,13 @@ public function build() { $messages_block_displayed = TRUE; } $build[$region][$key] = $this->blockViewBuilder->view($block); + + // The main content block cannot be cached: it is a placeholder for the + // render array returned by the controller. It should be rendered as-is, + // with other placed blocks "decorating" it. + if ($block_plugin instanceof MainContentBlockPluginInterface) { + unset($build[$region][$key]['#cache']['keys']); + } } if (!empty($build[$region])) { // \Drupal\block\BlockRepositoryInterface::getVisibleBlocksPerRegion() diff --git a/core/modules/system/src/Plugin/Block/SystemMainBlock.php b/core/modules/system/src/Plugin/Block/SystemMainBlock.php index 3d2d45e..2bb2479 100644 --- a/core/modules/system/src/Plugin/Block/SystemMainBlock.php +++ b/core/modules/system/src/Plugin/Block/SystemMainBlock.php @@ -9,7 +9,6 @@ use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\MainContentBlockPluginInterface; -use Drupal\Core\Form\FormStateInterface; /** * Provides a 'Main page content' block. @@ -42,26 +41,4 @@ public function build() { return $this->mainContent; } - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $form = parent::buildConfigurationForm($form, $form_state); - - // The main content block is never cacheable, because it may be dynamic. - $form['cache']['#disabled'] = TRUE; - $form['cache']['#description'] = $this->t('This block is never cacheable, it is not configurable.'); - $form['cache']['max_age']['#value'] = 0; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - // The main content block is never cacheable, because it may be dynamic. - return 0; - } - }