Last active
April 7, 2018 19:56
-
-
Save Greg-Boggs/3c15800b0e0915d0010dc7c401e5045f to your computer and use it in GitHub Desktop.
Helper function to get renderable region for Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example usage: $build = blocks_get_blocks_by_region('sidebar_first'); | |
function blocks_get_blocks_by_region($region_name) { | |
$build = []; | |
$blocks = entity_load_multiple_by_properties('block', ['theme' => $GLOBALS['theme'], 'region' => $region_name]); | |
uasort($blocks, 'Drupal\block\Entity\Block::sort'); | |
foreach ($blocks as $key => $block) { | |
if ($block->access('view)) { | |
$build[$key] = entity_view($block, 'block'); | |
} | |
} | |
return $build; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment