Loading core/modules/block_content/src/Entity/BlockContent.php +14 −10 Original line number Diff line number Diff line Loading @@ -126,6 +126,20 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { } } /** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); /** @var \Drupal\block_content\BlockContentInterface $block */ foreach ($entities as $block) { foreach ($block->getInstances() as $instance) { $instance->delete(); } } } /** * {@inheritdoc} */ Loading Loading @@ -162,16 +176,6 @@ public function preSaveRevision(EntityStorageInterface $storage, \stdClass $reco } } /** * {@inheritdoc} */ public function delete() { foreach ($this->getInstances() as $instance) { $instance->delete(); } parent::delete(); } /** * {@inheritdoc} */ Loading core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php +21 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\block_content\Entity\BlockContentType; use Drupal\Component\Plugin\PluginBase; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\block\Traits\BlockCreationTrait; /** * Tests that deleting a block clears the cached definitions. Loading @@ -14,6 +15,8 @@ */ class BlockContentDeletionTest extends KernelTestBase { use BlockCreationTrait; /** * {@inheritdoc} */ Loading Loading @@ -57,6 +60,24 @@ public function testDeletingBlockContentShouldClearPluginCache() { $block_content->delete(); // The plugin should no longer exist. $this->assertFalse($block_manager->hasDefinition($plugin_id)); // Create another block content entity. $block_content = BlockContent::create([ 'info' => 'Spiffy prototype', 'type' => 'spiffy', ]); $block_content->save(); $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); $block = $this->placeBlock($plugin_id, ['region' => 'content']); // Delete it via storage. $storage = $this->container->get('entity_type.manager')->getStorage('block_content'); $storage->delete([$block_content]); // The plugin should no longer exist. $this->assertFalse($block_manager->hasDefinition($plugin_id)); $this->assertNull($this->container->get('entity_type.manager')->getStorage('block')->loadUnchanged($block->id())); } } Loading
core/modules/block_content/src/Entity/BlockContent.php +14 −10 Original line number Diff line number Diff line Loading @@ -126,6 +126,20 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { } } /** * {@inheritdoc} */ public static function preDelete(EntityStorageInterface $storage, array $entities) { parent::preDelete($storage, $entities); /** @var \Drupal\block_content\BlockContentInterface $block */ foreach ($entities as $block) { foreach ($block->getInstances() as $instance) { $instance->delete(); } } } /** * {@inheritdoc} */ Loading Loading @@ -162,16 +176,6 @@ public function preSaveRevision(EntityStorageInterface $storage, \stdClass $reco } } /** * {@inheritdoc} */ public function delete() { foreach ($this->getInstances() as $instance) { $instance->delete(); } parent::delete(); } /** * {@inheritdoc} */ Loading
core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php +21 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\block_content\Entity\BlockContentType; use Drupal\Component\Plugin\PluginBase; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\block\Traits\BlockCreationTrait; /** * Tests that deleting a block clears the cached definitions. Loading @@ -14,6 +15,8 @@ */ class BlockContentDeletionTest extends KernelTestBase { use BlockCreationTrait; /** * {@inheritdoc} */ Loading Loading @@ -57,6 +60,24 @@ public function testDeletingBlockContentShouldClearPluginCache() { $block_content->delete(); // The plugin should no longer exist. $this->assertFalse($block_manager->hasDefinition($plugin_id)); // Create another block content entity. $block_content = BlockContent::create([ 'info' => 'Spiffy prototype', 'type' => 'spiffy', ]); $block_content->save(); $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); $block = $this->placeBlock($plugin_id, ['region' => 'content']); // Delete it via storage. $storage = $this->container->get('entity_type.manager')->getStorage('block_content'); $storage->delete([$block_content]); // The plugin should no longer exist. $this->assertFalse($block_manager->hasDefinition($plugin_id)); $this->assertNull($this->container->get('entity_type.manager')->getStorage('block')->loadUnchanged($block->id())); } }