function block_rebuild in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/block/block.module \block_rebuild()
Implements hook_rebuild().
File
- core/
modules/ block/ block.module, line 139 - Controls the visual building blocks a page is constructed with.
Code
function block_rebuild() {
foreach (\Drupal::service('theme_handler')
->listInfo() as $theme => $data) {
if ($data->status) {
$regions = system_region_list($theme);
/** @var \Drupal\block\BlockInterface[] $blocks */
$blocks = entity_load_multiple_by_properties('block', [
'theme' => $theme,
]);
foreach ($blocks as $block_id => $block) {
// Disable blocks in invalid regions.
$region = $block
->getRegion();
if ($region !== BlockInterface::BLOCK_REGION_NONE) {
if (!empty($region) && !isset($regions[$region]) && $block
->status()) {
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', [
'%info' => $block_id,
'%region' => $region,
]), 'warning');
$block
->disable();
}
// Set region to none if not enabled.
if (!$block
->status()) {
$block
->setRegion(BlockInterface::BLOCK_REGION_NONE);
$block
->save();
}
}
}
}
}
}