diff --git a/core/modules/block/lib/Drupal/block/BlockStorageController.php b/core/modules/block/lib/Drupal/block/BlockStorageController.php index 9cdf1a7..3997704 100644 --- a/core/modules/block/lib/Drupal/block/BlockStorageController.php +++ b/core/modules/block/lib/Drupal/block/BlockStorageController.php @@ -16,6 +16,17 @@ class BlockStorageController extends ConfigStorageController { /** + * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::load(). + */ + public function load(array $ids = NULL) { + $entities = parent::load($ids); + // Only blocks with a valid plugin should be loaded. + return array_filter($entities, function ($entity) { + return $entity->getPlugin(); + }); + } + + /** * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::loadByProperties(). */ public function loadByProperties(array $values = array()) { diff --git a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php index 572d5e1..775ecfa 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php @@ -10,6 +10,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Component\Plugin\Exception\PluginException; /** * Defines a Block configuration entity class. @@ -132,13 +133,27 @@ class Block extends ConfigEntityBase { public function __construct(array $values, $entity_type) { parent::__construct($values, $entity_type); - $this->instance = drupal_container()->get('plugin.manager.block')->createInstance($this->plugin, $this->configuration); - $this->configuration += $this->instance->getConfig(); + // @todo Consider moving to Block::getPlugin(). + try { + $this->instance = drupal_container()->get('plugin.manager.block')->createInstance($this->plugin, $this->configuration); + $this->configuration += $this->instance->getConfig(); + } + catch (PluginException $e) { + // Ignore blocks belonging to disabled modules, but re-throw valid + // exceptions when the module is enabled and the plugin is misconfigured. + if (module_exists($this->module)) { + throw $e; + } + } + // @todo Consider moving to \Drupal\block\BlockStorageController::create(). + if (!$this->module) { + $definition = $this->instance->getDefinition(); + $this->module = $definition['module']; + } if (isset($this->configuration['cache'])) { $this->cache = $this->configuration['cache']; } - if (!isset($this->theme) && $id = $this->id()) { list($this->theme) = explode('.', $id); } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php index dc93755..22f47e8 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockLibrarySearchTest.php @@ -54,6 +54,7 @@ function testBlockLibrarySearch() { // Check that the block search form redirects to the correct block form. $this->drupalPost('admin/structure/block/list/block_plugin_ui:stark/add', array('block' => 'system_main_block'), t('Next')); - $this->assertUrl('admin/structure/block/manage/system_main_block/stark'); + $this->assertUrl('admin/structure/block/add/system_main_block/stark'); } + } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php index 089b9a7..c469eb6 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php @@ -40,15 +40,21 @@ function testBlockThemeHookSuggestions() { $block = entity_create('block', array( 'plugin' => 'system_menu_block:menu-admin', 'region' => 'footer', + 'id' => variable_get('theme_default', 'stark') . '.machinename', )); $variables = array(); $variables['elements']['#block'] = $block; + $variables['elements']['#block_config'] = $block->getPlugin()->getConfig() + array( + 'id' => $block->get('plugin'), + 'region' => $block->get('region'), + 'module' => $block->get('module'), + ); $variables['elements']['#children'] = ''; // Test adding a class to the block content. $variables['content_attributes']['class'][] = 'test-class'; template_preprocess_block($variables); - $this->assertEqual($variables['theme_hook_suggestions'], array('block__footer', 'block__system', 'block__system_menu_block', 'block__system_menu_block__menu_admin')); + $this->assertEqual($variables['theme_hook_suggestions'], array('block__footer', 'block__system', 'block__system_menu_block', 'block__system_menu_block__menu_admin', 'block__machinename')); $this->assertEqual($variables['content_attributes']['class'], array('test-class', 'content'), 'Default .content class added to block content_attributes_array'); } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php index c5cc7f5..274ddb2 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@ -389,7 +389,7 @@ function testBlockModuleDisable() { } $this->drupalGet(''); foreach ($regions as $region) { - $this->assertText($blocks[$region]['subject']); + $this->assertText($blocks[$region]->label()); } // Disable the block test module and refresh the definitions cache. @@ -405,7 +405,7 @@ function testBlockModuleDisable() { // Ensure that the disabled module's block instance is not listed. foreach ($regions as $region) { - $this->assertNoText($blocks[$region]['subject']); + $this->assertNoText($blocks[$region]->label()); } // Ensure that the disabled module's block plugin is no longer available. @@ -416,7 +416,7 @@ function testBlockModuleDisable() { $this->drupalGet(''); $this->assertResponse(200); foreach ($regions as $region) { - $this->assertNoText($blocks[$region]['subject']); + $this->assertNoText($blocks[$region]->label()); } // Confirm that a different block instance can still be enabled by @@ -424,16 +424,16 @@ function testBlockModuleDisable() { // Emulate a POST submission rather than using drupalPlaceBlock() to ensure // that the form still functions as expected. $edit = array( - 'title' => $this->randomName(8), + 'label' => $this->randomName(8), 'machine_name' => $this->randomName(8), 'region' => 'sidebar_first', ); - $this->drupalPost('admin/structure/block/manage/system_powered_by_block/stark', $edit, t('Save block')); + $this->drupalPost('admin/structure/block/add/system_powered_by_block/stark', $edit, t('Save block')); $this->assertText(t('The block configuration has been saved.')); - $this->assertText($edit['title']); + $this->assertText($edit['label']); // Update the weight of a block. - $edit = array('blocks[0][weight]' => -1); + $edit = array('blocks[stark.' . $edit['machine_name'] . '][weight]' => -1); $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); $this->assertText(t('The block settings have been updated.')); @@ -445,7 +445,7 @@ function testBlockModuleDisable() { // Reload the admin page and confirm the block can again be configured. $this->drupalGet('admin/structure/block'); foreach ($regions as $region) { - $this->assertLinkByHref(url('admin/structure/block/manage/' . $blocks[$region]['config_id'] . '/stark/config')); + $this->assertLinkByHref(url('admin/structure/block/manage/' . $blocks[$region]->id())); } // Confirm that the blocks are again displayed on the front page in the @@ -453,14 +453,14 @@ function testBlockModuleDisable() { $this->drupalGet(''); foreach ($regions as $region) { // @todo Use a proper method for this. - $name_pieces = explode('.', $blocks[$region]['config_id']); + $name_pieces = explode('.', $blocks[$region]->id()); $machine_name = array_pop($name_pieces); $xpath = $this->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array( ':region-class' => 'region region-' . drupal_html_class($region), ':block-id' => 'block-' . strtr(strtolower($machine_name), '-', '_'), )); $this->assertFieldByXPath($xpath, NULL, format_string('Block %name found in the %region region.', array( - '%name' => $blocks[$region]['subject'], + '%name' => $blocks[$region]->label(), '%region' => $region, ))); }