diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 19a1301..5b30b4a 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -146,7 +146,10 @@ function block_rebuild() { // Disable blocks in invalid regions. if (!isset($regions[$block->getRegion()]) && $block->status()) { drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()]), 'warning'); - $block->disable()->save(); + $block + ->setRegion(system_default_region($theme)) + ->disable() + ->save(); } } } diff --git a/core/modules/block/tests/src/Kernel/BlockRebuildTest.php b/core/modules/block/tests/src/Kernel/BlockRebuildTest.php index 13bacff..e2d555d 100644 --- a/core/modules/block/tests/src/Kernel/BlockRebuildTest.php +++ b/core/modules/block/tests/src/Kernel/BlockRebuildTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\block\Kernel; use Drupal\block\BlockInterface; +use Drupal\block\Entity\Block; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\KernelTests\KernelTestBase; use Drupal\simpletest\BlockCreationTrait; @@ -67,11 +68,18 @@ public function testRebuildNoInvalidBlocks() { public function testRebuildInvalidBlocks() { $this->placeBlock('system_powered_by_block', ['region' => 'content', 'theme' => 'classy']); $block = $this->placeBlock('system_powered_by_block', ['region' => 'INVALID', 'theme' => 'classy']); + $this->assertSame('INVALID', $block->getRegion()); + $this->assertTrue($block->status()); block_rebuild(); + // Reload block entity. + $block = Block::load($block->id()); + $messages = drupal_get_messages(); $expected = ['warning' => [new TranslatableMarkup('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block->id(), '%region' => 'INVALID'])]]; $this->assertEquals($expected, $messages); + $this->assertSame(system_default_region('classy'), $block->getRegion()); + $this->assertFalse($block->status()); } }