You are here

public function ContextBlockPageVariant::build in Context 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/DisplayVariant/ContextBlockPageVariant.php \Drupal\context\Plugin\DisplayVariant\ContextBlockPageVariant::build()
  2. 8.0 src/Plugin/DisplayVariant/ContextBlockPageVariant.php \Drupal\context\Plugin\DisplayVariant\ContextBlockPageVariant::build()

Builds and returns the renderable array for the display variant.

The variant can contain cacheability metadata for the configuration that was passed in setConfiguration(). In the build() method, this should be added to the render array that is returned.

Return value

array A render array for the display variant.

Overrides VariantInterface::build

File

src/Plugin/DisplayVariant/ContextBlockPageVariant.php, line 96

Class

ContextBlockPageVariant
Provides a page display variant that decorates the main content with blocks.

Namespace

Drupal\context\Plugin\DisplayVariant

Code

public function build() {
  $build = [
    '#cache' => [
      'tags' => [
        'context_block_page',
        $this
          ->getPluginId(),
      ],
    ],
  ];

  // Place main content block, it will be removed by the reactions if a main
  // content block has been manually placed.
  $build['content']['system_main'] = $this->mainContent;

  // Execute each block reaction and let them modify the page build.
  foreach ($this->contextManager
    ->getActiveReactions('blocks') as $reaction) {
    $build = $reaction
      ->execute($build, $this->title, $this->mainContent);
  }

  // Execute each block reaction and check if default block should be included in page build.
  foreach ($this->contextManager
    ->getActiveReactions('blocks') as $reaction) {
    if ($reaction
      ->includeDefaultBlocks()) {
      $build = NestedArray::mergeDeep($this
        ->getBuildFromBlockLayout(), $build);
      return $build;
    }
  }
  return $build;
}