function _block_skinr_load_blocks in Skinr 8.2
Same name and namespace in other branches
- 7.2 modules/block.skinr.inc \_block_skinr_load_blocks()
Returns a list of enabled blocks for a given theme.
Based on _block_rehash(), but without the blocks table rebuild part.
Return value
Block[] An array of blocks.
See also
_block_rehash()
2 calls to _block_skinr_load_blocks()
- block_skinr_ui_element_options in modules/
block.skinr.inc - Implements hook_skinr_ui_element_options().
- block_skinr_ui_element_title in modules/
block.skinr.inc - Implements hook_skinr_ui_element_title().
File
- modules/
block.skinr.inc, line 81 - Implements Skinr hooks for block.module.
Code
function _block_skinr_load_blocks($theme) {
$cache =& drupal_static(__FUNCTION__, array());
if (!isset($cache['blocks'][$theme])) {
$cache['blocks'][$theme] = array();
$regions = system_region_list($theme);
/** @var Block[] $blocks */
$blocks = \Drupal::entityManager()
->getStorage('block')
->loadByProperties(array(
'theme' => $theme,
));
foreach ($blocks as $block_id => $block) {
// Remove any invalid block from the list.
// @todo Remove this check as part of https://drupal.org/node/1776830.
if (!$block
->getPlugin()) {
unset($blocks[$block_id]);
continue;
}
$region = $block
->get('region');
$status = $block
->status();
// Skip blocks in invalid regions.
if (!empty($region) && $region != BlockInterface::BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
continue;
}
// Skip if not enabled.
if (!$status) {
continue;
}
$cache['blocks'][$theme][$block_id] = $block;
}
asort($cache['blocks'][$theme]);
}
return $cache['blocks'][$theme];
}