core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php | 6 ++---- .../block/src/Plugin/DisplayVariant/FullPageVariant.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php b/core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php index df1b52a..3c05cf3 100644 --- a/core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php +++ b/core/lib/Drupal/Core/Display/Annotation/DisplayVariant.php @@ -25,10 +25,8 @@ * * Plugin namespace: Plugin\DisplayVariant * - * For working examples, see - * - \Drupal\system\Plugin\DisplayVariant\SimplePageVariant - * - \Drupal\block\Plugin\DisplayVariant\BlockPageVariant - * - \Drupal\block\Plugin\DisplayVariant\DemoBlockPageVariant + * For a working example, see + * \Drupal\block\Plugin\DisplayVariant\FullPageVariant * * @see \Drupal\Core\Display\VariantInterface * @see \Drupal\Core\Display\VariantBase diff --git a/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php b/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php index dc91b8b..a927dd4 100644 --- a/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php +++ b/core/modules/block/src/Plugin/DisplayVariant/FullPageVariant.php @@ -20,7 +20,7 @@ /** * Provides a display variant that represents the full page. * - * @DisplayVariant( + * @PageDisplayVariant( * id = "full_page", * admin_label = @Translation("Full page") * ) @@ -132,6 +132,9 @@ protected function getTheme() { * {@inheritdoc} */ public function build() { + // Track whether a block that shows the main content is displayed or not. + $main_content_block_displayed = FALSE; + $build = array(); // Load all region content assigned via blocks. foreach ($this->getRegionAssignments() as $region => $blocks) { @@ -140,6 +143,7 @@ public function build() { if ($block->access('view')) { if ($block->getPlugin() instanceof MainContentBlockPluginInterface) { $block->getPlugin()->setMainContent($this->mainContent); + $main_content_block_displayed = TRUE; } $build[$region][$key] = $this->blockViewBuilder->view($block); } @@ -149,6 +153,14 @@ public function build() { $build[$region]['#sorted'] = TRUE; } } + + // If no block that shows the main content is displayed, still show the main + // content. Otherwise the end user will see all displayed blocks, but not + // the main content they came for. + if (!$main_content_block_displayed) { + $build['content']['system_main'] = $this->mainContent; + } + return $build; }