public function UltimenuManager::getBlocksByRegion in Ultimenu 8.2
Same name and namespace in other branches
- 8 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".
array $config: The config available for the menu tree.
Return value
array The renderable array of blocks within the region.
Overrides UltimenuManagerInterface::getBlocksByRegion
1 call to UltimenuManager::getBlocksByRegion()
- UltimenuManager::buildFlyout in src/
UltimenuManager.php - Returns the renderable array region data.
File
- src/
UltimenuManager.php, line 550
Class
- UltimenuManager
- Implements UltimenuManagerInterface.
Namespace
Drupal\ultimenuCode
public function getBlocksByRegion($region, array $config) {
if (!isset($this->blocks[$region])) {
$build = [];
$blocks = $this->entityTypeManager
->getStorage('block')
->loadByProperties([
'theme' => $this
->getThemeDefault(),
'region' => $region,
]);
if ($blocks) {
uasort($blocks, 'Drupal\\block\\Entity\\Block::sort');
// Only provides extra access checks if the region is ajaxified.
if (empty($config['ajaxify'])) {
foreach ($blocks as $key => $block) {
if ($block
->access('view')) {
$build[$key] = $this->entityTypeManager
->getViewBuilder($block
->getEntityTypeId())
->view($block, 'block');
}
}
}
else {
foreach ($blocks as $key => $block) {
if ($this->tool
->isAllowedBlock($block, $config)) {
$build[$key] = $this->entityTypeManager
->getViewBuilder($block
->getEntityTypeId())
->view($block, 'block');
}
}
}
}
$this->blocks[$region] = $build;
}
return $this->blocks[$region];
}