Returns an array of block class instances by theme.
$theme: The theme to rehash blocks for. If not provided, defaults to the currently used theme.
Blocks currently exported by modules.
function _block_rehash($theme = NULL) {
$theme = $theme ? $theme : config('system.theme')
->get('default');
$regions = system_region_list($theme);
$blocks = entity_load_multiple_by_properties('block', array(
'theme' => $theme,
));
foreach ($blocks as $block_id => $block) {
$region = $block
->get('region');
$status = $block
->status();
// Disable blocks in invalid regions.
if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array(
'%info' => $block_id,
'%region' => $region,
)), 'warning');
// Disabled modules are moved into the BLOCK_REGION_NONE later so no
// need to move the block to another region.
$block
->disable()
->save();
}
// Set region to none if not enabled.
if (!$status) {
$block
->set('region', BLOCK_REGION_NONE);
$block
->save();
}
}
return $blocks;
}