You are here

public function ViewsBlockArea::render in Views block area 8

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

Overrides AreaPluginBase::render

File

src/Plugin/views/area/ViewsBlockArea.php, line 130
Contains \Drupal\block\Plugin\views\area\Block.

Class

ViewsBlockArea
Provides an area handler which renders a block entity in a certain view mode.

Namespace

Drupal\views_block_area\Plugin\views\area

Code

public function render($empty = FALSE) {
  $element = [];

  /** @var \Drupal\block_field\BlockFieldItemInterface $item */
  $block_instance = $this
    ->getBlock();

  // Make sure the block exists and is accessible.
  if (!$block_instance || !$block_instance
    ->access(\Drupal::currentUser())) {
    return NULL;
  }

  // @see \Drupal\block\BlockViewBuilder::buildPreRenderableBlock
  // @see template_preprocess_block()
  $element = [
    '#theme' => 'block',
    '#attributes' => [],
    '#configuration' => $block_instance
      ->getConfiguration(),
    '#plugin_id' => $block_instance
      ->getPluginId(),
    '#base_plugin_id' => $block_instance
      ->getBaseId(),
    '#derivative_plugin_id' => $block_instance
      ->getDerivativeId(),
    '#id' => $block_instance
      ->getPluginId(),
    'content' => $block_instance
      ->build(),
  ];

  /** @var \Drupal\Core\Render\RendererInterface $renderer */
  $renderer = $this->renderer;
  $renderer
    ->addCacheableDependency($element, $block_instance);
  return $element;
}