function block_rebuild
Same name in other branches
- 8.9.x core/modules/block/block.module \block_rebuild()
- 10 core/modules/block/block.module \block_rebuild()
- 11.x core/modules/block/block.module \block_rebuild()
Implements hook_rebuild().
8 calls to block_rebuild()
- BlockRebuildTest::testRebuildInvalidBlocks in core/
modules/ block/ tests/ src/ Kernel/ BlockRebuildTest.php - @covers ::block_rebuild
- BlockRebuildTest::testRebuildNoBlocks in core/
modules/ block/ tests/ src/ Kernel/ BlockRebuildTest.php - @covers ::block_rebuild
- BlockRebuildTest::testRebuildNoInvalidBlocks in core/
modules/ block/ tests/ src/ Kernel/ BlockRebuildTest.php - @covers ::block_rebuild
- MigrateBlockContentTranslationTest::setUp in core/
modules/ block/ tests/ src/ Kernel/ Migrate/ d6/ MigrateBlockContentTranslationTest.php - MigrateBlockContentTranslationTest::setUp in core/
modules/ block/ tests/ src/ Kernel/ Migrate/ d7/ MigrateBlockContentTranslationTest.php
File
-
core/
modules/ block/ block.module, line 168
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 = \Drupal::entityTypeManager()->getStorage('block')
->loadByProperties([
'theme' => $theme,
]);
foreach ($blocks as $block_id => $block) {
// Disable blocks in invalid regions.
if (!isset($regions[$block->getRegion()])) {
if ($block->status()) {
\Drupal::messenger()->addWarning(t('The block %info was assigned to the invalid region %region and has been disabled.', [
'%info' => $block_id,
'%region' => $block->getRegion(),
]));
}
$block->setRegion(system_default_region($theme))
->disable()
->save();
}
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.