function block_rebuild
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(); } } } } } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!block!block.module/function/block_rebuild/8.1.x