diff -u b/core/modules/block/block.module b/core/modules/block/block.module --- b/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -357,8 +357,26 @@ $instances = array(); $theme = $theme ? $theme : variable_get('theme_default', 'stark'); $block_configs = config_get_storage_names_with_prefix('plugin.core.block.' . $theme); + $regions = system_region_list($theme); foreach ($block_configs as $config) { $blocks[$config] = block_load($config); + $config = config($config); + $region = $config->get('region'); + $status = $config->get('status'); + // Disable blocks in invalid regions. + if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status == 1) { + drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $config->get('id'), '%region' => $region)), 'warning'); + // Disabled modules are moved into the BLOCK_REGION_NONE later so no + // need to move the block to another region. + $config->set('status', 0); + $config->save(); + } + // Set region to none if not enabled and make sure status is set. + if (empty($status)) { + $config->set('region', BLOCK_REGION_NONE); + $config->set('status', 0); + $config->save(); + } } return $blocks; } diff -u b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php --- b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php @@ -19,7 +19,7 @@ * * @var array */ - public static $modules = array('block', 'block_test'); + public static $modules = array('block', 'block_test', 'views'); protected $admin_user; protected $normal_user; only in patch2: unchanged: --- a/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php @@ -32,7 +32,11 @@ public static function getInfo() { function setUp() { parent::setUp(); // Create an admin user. - $admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages')); + $admin_user = $this->drupalCreateUser(array( + 'administer site configuration', + 'access administration pages', + 'administer blocks', + )); $this->drupalLogin($admin_user); } @@ -41,20 +45,21 @@ function setUp() { */ function testBlockInInvalidRegion() { // Enable a test block in the default theme and place it in an invalid region. - db_merge('block') - ->key(array( - 'module' => 'block_test', - 'delta' => 'test_html_id', - 'theme' => variable_get('theme_default', 'stark'), - )) - ->fields(array( - 'status' => 1, - 'region' => 'invalid_region', - 'cache' => DRUPAL_NO_CACHE, - )) - ->execute(); + $current_theme = variable_get('default_theme', 'stark'); + $machine_name = 'test_html_id'; + $block = array( + 'machine_name' => $machine_name, + 'region' => 'footer', + ); + $this->drupalPost("admin/structure/block/manage/test_html_id/$current_theme", $block, t('Save block')); + $this->assertText(t('The block configuration has been saved.'), 'Block was saved.'); + + $machine_name = 'plugin.core.block.' . $current_theme . '.' . $machine_name; + $config = config($machine_name); + $config->set('region', 'invalid_region'); + $config->save(); - $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => t('Test block html id'), '%region' => 'invalid_region')); + $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $config->get('id'), '%region' => 'invalid_region')); // Clearing the cache should disable the test block placed in the invalid region. $this->drupalPost('admin/config/development/performance', array(), 'Clear all caches'); @@ -65,17 +70,9 @@ function testBlockInInvalidRegion() { $this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.'); // Place disabled test block in the invalid region of the default theme. - db_merge('block') - ->key(array( - 'module' => 'block_test', - 'delta' => 'test_html_id', - 'theme' => variable_get('theme_default', 'stark'), - )) - ->fields(array( - 'region' => 'invalid_region', - 'cache' => DRUPAL_NO_CACHE, - )) - ->execute(); + $config = config($machine_name); + $config->set('region', 'invalid_region'); + $config->save(); // Clear the cache to check if the warning message is not triggered. $this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');