You are here

public function UltimenuManager::getBlocksByRegion in Ultimenu 8

Same name and namespace in other branches
  1. 8.2 src/UltimenuManager.php \Drupal\ultimenu\UltimenuManager::getBlocksByRegion()

A helper function to generate a list of blocks from a specified region.

Parameters

string $region: The string identifier for a Ultimenu region. e.g. "ultimenu_main_about".

Return value

array The renderable array of blocks within the region.

Overrides UltimenuManagerInterface::getBlocksByRegion

1 call to UltimenuManager::getBlocksByRegion()
UltimenuManager::buildDataRegion in src/UltimenuManager.php
Returns the renderable array region data.

File

src/UltimenuManager.php, line 534

Class

UltimenuManager
Manages Ultimenu plugin.

Namespace

Drupal\ultimenu

Code

public function getBlocksByRegion($region) {
  $build = [];
  $theme = $this
    ->getConfig('system.theme')
    ->get('default');
  $blocks = $this->entityTypeManager
    ->getStorage('block')
    ->loadByProperties([
    'theme' => $theme,
    'region' => $region,
  ]);
  if ($blocks) {
    uasort($blocks, 'Drupal\\block\\Entity\\Block::sort');
    foreach ($blocks as $key => $block) {
      if ($block
        ->access('view')) {
        $build[$key] = $this->entityTypeManager
          ->getViewBuilder($block
          ->getEntityTypeId())
          ->view($block, 'block');
      }
    }
  }
  return $build;
}