diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 4a4ae5a..0583395 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -286,16 +286,18 @@ function block_configurable_language_delete(ConfigurableLanguageInterface $langu /** * Implements hook_node_type_delete(). * - * Delete the potential block visibility settings of the deleted node bundles. + * Delete the potential block visibility settings of the deleted node bundle. */ function block_node_type_delete(NodeTypeInterface $node_type) { - foreach (Block::loadMultiple() as $block) { - /** @var $block \Drupal\block\BlockInterface */ + $ids = \Drupal::entityQuery('block') + ->condition('visibility.node_type.bundles.*', $node_type->id()) + ->execute(); + + /** @var $block \Drupal\block\BlockInterface */ + foreach (Block::loadMultiple($ids) as $block) { $visibility = $block->getVisibility(); - if (isset($visibility['node_type']['bundles'][$node_type->id()])) { - unset($visibility['node_type']['bundles'][$node_type->id()]); - $block->setVisibilityConfig('node_type', $visibility['node_type']); - $block->save(); - } + unset($visibility['node_type']['bundles'][$node_type->id()]); + $block->setVisibilityConfig('node_type', $visibility['node_type']); + $block->save(); } } diff --git a/core/modules/block/src/Tests/BlockTest.php b/core/modules/block/src/Tests/BlockTest.php index a9776b5..5ee7865 100644 --- a/core/modules/block/src/Tests/BlockTest.php +++ b/core/modules/block/src/Tests/BlockTest.php @@ -486,7 +486,7 @@ public function testBlockUserRoleDelete() { */ public function testBlockNodeTypeDelete() { // Enable the node module. - \Drupal::moduleHandler()->install(['node']); + \Drupal::service('module_installer')->install(['node']); $node_type1 = $this->drupalCreateContentType(); $node_type2 = $this->drupalCreateContentType();