From c90b15c774a35c52da5451ec9443ba4776a695da Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Sun, 28 Aug 2016 22:20:49 +0100 Subject: [PATCH] Revert "Issue #2786195 by larowlan: Deleted block is not removed from the block list" This reverts commit 82bece91c3a3b28c25c8dc3817188a87b1942a14. --- .../block_content/src/Entity/BlockContent.php | 18 +----- .../src/Plugin/Derivative/BlockContent.php | 2 - .../src/Kernel/BlockContentDeletionTest.php | 61 ------------------- 3 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php diff --git a/core/modules/block_content/src/Entity/BlockContent.php b/core/modules/block_content/src/Entity/BlockContent.php index 13af342934b4..9e0531e6da79 100644 --- a/core/modules/block_content/src/Entity/BlockContent.php +++ b/core/modules/block_content/src/Entity/BlockContent.php @@ -105,15 +105,9 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); - static::invalidateBlockPluginCache(); - } - /** - * {@inheritdoc} - */ - public static function postDelete(EntityStorageInterface $storage, array $entities) { - parent::postDelete($storage, $entities); - static::invalidateBlockPluginCache(); + // Invalidate the block cache to update custom block-based derivatives. + \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); } /** @@ -290,12 +284,4 @@ class BlockContent extends ContentEntityBase implements BlockContentInterface { return $this; } - /** - * Invalidates the block plugin cache after changes and deletions. - */ - protected static function invalidateBlockPluginCache() { - // Invalidate the block cache to update custom block-based derivatives. - \Drupal::service('plugin.manager.block')->clearCachedDefinitions(); - } - } diff --git a/core/modules/block_content/src/Plugin/Derivative/BlockContent.php b/core/modules/block_content/src/Plugin/Derivative/BlockContent.php index ab564451cb28..63b68c07dc9b 100644 --- a/core/modules/block_content/src/Plugin/Derivative/BlockContent.php +++ b/core/modules/block_content/src/Plugin/Derivative/BlockContent.php @@ -44,8 +44,6 @@ class BlockContent extends DeriverBase implements ContainerDeriverInterface { */ public function getDerivativeDefinitions($base_plugin_definition) { $block_contents = $this->blockContentStorage->loadMultiple(); - // Reset the discovered definitions. - $this->derivatives = []; /** @var $block_content \Drupal\block_content\Entity\BlockContent */ foreach ($block_contents as $block_content) { $this->derivatives[$block_content->uuid()] = $base_plugin_definition; diff --git a/core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php b/core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php deleted file mode 100644 index d7a9444e8e7e..000000000000 --- a/core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php +++ /dev/null @@ -1,61 +0,0 @@ -installEntitySchema('block_content'); - } - - /** - * Tests deleting a block_content updates the discovered block plugin. - */ - public function testDeletingBlockContentShouldClearPluginCache() { - // Create a block content type. - $block_content_type = BlockContentType::create([ - 'id' => 'spiffy', - 'label' => 'Mucho spiffy', - 'description' => "Provides a block type that increases your site's spiffiness by upto 11%", - ]); - $block_content_type->save(); - // And a block content entity. - $block_content = BlockContent::create([ - 'info' => 'Spiffy prototype', - 'type' => 'spiffy', - ]); - $block_content->save(); - - // Make sure the block content provides a derivative block plugin in the - // block repository. - /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */ - $block_manager = $this->container->get('plugin.manager.block'); - $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); - $this->assertTrue($block_manager->hasDefinition($plugin_id)); - - // Now delete the block content entity. - $block_content->delete(); - // The plugin should no longer exist. - $this->assertFalse($block_manager->hasDefinition($plugin_id)); - } - -}