You are here

public function PanelsEverywhereDisplayVariant::build in Panels Everywhere 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/DisplayVariant/PanelsEverywhereDisplayVariant.php \Drupal\panels_everywhere\Plugin\DisplayVariant\PanelsEverywhereDisplayVariant::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/PanelsEverywhereDisplayVariant.php, line 62

Class

PanelsEverywhereDisplayVariant
Provides a display variant that simply contains blocks.

Namespace

Drupal\panels_everywhere\Plugin\DisplayVariant

Code

public function build() {
  $main_content_included = NULL;
  $this
    ->setPageTitle($this->title);
  foreach ($this
    ->getRegionAssignments() as $region => $blocks) {
    if (!$blocks) {
      continue;
    }
    foreach ($blocks as $block_id => $block) {
      if ($block instanceof MainContentBlockPluginInterface) {
        $block
          ->setMainContent($this->mainContent);
        $main_content_included = array(
          $region,
          $block_id,
        );
      }
    }
  }

  // Build it the render array!
  $build = parent::build();

  // Copied from BlockPageVariant.php.
  // 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 (!empty($main_content_included)) {
    list($region, $block_id) = $main_content_included;
    unset($build[$region][$block_id]['#cache']['keys']);
  }
  return $build;
}