You are here

public function DsRegionBlock::build in Display Suite 8.3

Same name and namespace in other branches
  1. 8.2 modules/ds_extras/src/Plugin/Block/DsRegionBlock.php \Drupal\ds_extras\Plugin\Block\DsRegionBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

modules/ds_extras/src/Plugin/Block/DsRegionBlock.php, line 24

Class

DsRegionBlock
Provides the region block plugin.

Namespace

Drupal\ds_extras\Plugin\Block

Code

public function build() {
  $id = $this
    ->getDerivativeId();
  $data = drupal_static('ds_block_region');
  if (!empty($data[$id])) {
    $output = '';
    foreach (Element::children($data[$id]) as $key) {
      if (!empty($data[$id][$key])) {
        $output .= \Drupal::service('renderer')
          ->render($data[$id][$key]);
      }
    }
    return [
      '#markup' => Markup::create($output),
    ];
  }
  else {
    return [];
  }
}