diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 6466b60..5fc7c6a 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -363,6 +363,7 @@ function _block_rehash($theme = NULL) { $block_configs = config_get_storage_names_with_prefix('plugin.core.block.' . $theme); $regions = system_region_list($theme); foreach ($block_configs as $config) { + // Only list valid block instances. if (!$block = block_load($config)) { continue; } @@ -477,15 +478,20 @@ function block_list($region) { * * @return * A block object. + * + * @todo Add block_load_multiple() and make this function a single-value wrapper. */ function block_load($plugin_id, array $conf = array()) { $manager = drupal_container()->get('plugin.manager.block'); if (!$block = $manager->getInstance(array('config' => $plugin_id))) { + // If the block instance does not exist, try to create it. try { $block = $manager->createInstance($plugin_id, $conf); } catch (PluginException $e) { $config = config($plugin_id)->get(); + // Ignore blocks belonging to disabled modules, but re-throw valid + // exceptions when the module is enabled and the plugin is misconfigured. if (module_exists($config['module'])) { throw $e; } @@ -500,6 +506,8 @@ function block_load($plugin_id, array $conf = array()) { * * @return * An array of blocks grouped by region. + * + * @todo Remove this function, and replace it with a block_load_multiple(). */ function _block_load_blocks() { global $theme; @@ -513,6 +521,8 @@ function _block_load_blocks() { } else { $config = config($plugin_id)->get(); + // Ignore blocks belonging to disabled modules, but re-throw valid + // exceptions when the module is enabled and the plugin is misconfigured. if (module_exists($config['module'])) { throw new PluginException(sprintf('The plugin %s was not found.', $plugin_id)); } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 8c8ddde..7928fa9 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -381,7 +381,7 @@ function testBlockRehash() { } /** - * Test disabled blocks. + * Tests blocks belonging to disabled modules. */ function testBlockModuleDisable() { module_enable(array('block_test')); @@ -400,10 +400,22 @@ function testBlockModuleDisable() { $block['region'] = 'header'; $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); + // Disable the block test module and refresh the definitions cache. module_disable(array('block_test'), FALSE); + $manager->clearCachedDefinitions(); + + // Ensure that the block administration page still functions as expected. $this->drupalGet('admin/structure/block'); $this->assertResponse(200); - $this->assertTitle('Blocks'); + // A 200 response is possible with a fatal error, so check the title too. + $this->assertTitle(t('Blocks | Drupal')); + + // Ensure that the disabled module's block instance is not listed. + $this->assertNoText(t('Test block caching')); + + // Ensure that the disabled module's block plugin is no longer available. + $this->drupalGet('admin/structure/block/list/block_plugin_ui:' . variable_get('theme_default', 'stark') . '/add'); + $this->assertNoText(t('Test block caching')); } }