diff --git a/core/includes/language.inc b/core/includes/language.inc index 976dd75..74cc832 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -8,6 +8,8 @@ */ use Drupal\Core\Language\Language; +use Drupal\block\BlockPluginEvents; +use Symfony\Component\EventDispatcher\GenericEvent; /** * No language negotiation. The default language is used. @@ -209,6 +211,11 @@ function language_types_disable($types) { foreach ($types as $type) { unset($enabled_types[$type]); + // Inform the block plugin system you have removed a language. + if (\Drupal::moduleHandler()->moduleExists('block')) { + $event = new GenericEvent('language_block:' . $type); + \Drupal::service('event_dispatcher')->dispatch(BlockPluginEvents::PERMANENTLY_UNAVAILABLE, $event); + } } variable_set('language_types', $enabled_types); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php index 74dfc25..309da01 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php @@ -12,6 +12,8 @@ use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; use Drupal\custom_block\CustomBlockInterface; +use Drupal\block\BlockPluginEvents; +use Symfony\Component\EventDispatcher\GenericEvent; /** * Defines the custom block entity class. @@ -225,9 +227,8 @@ public function preSaveRevision(EntityStorageControllerInterface $storage_contro * {@inheritdoc} */ public function delete() { - foreach ($this->getInstances() as $instance) { - $instance->delete(); - } + $event = new GenericEvent('custom_block:' . $this->uuid->value); + \Drupal::service('event_dispatcher')->dispatch(BlockPluginEvents::PERMANENTLY_UNAVAILABLE, $event); parent::delete(); } diff --git a/core/modules/block/lib/Drupal/block/BlockPluginEvents.php b/core/modules/block/lib/Drupal/block/BlockPluginEvents.php index 5ae4798..c4afebe 100644 --- a/core/modules/block/lib/Drupal/block/BlockPluginEvents.php +++ b/core/modules/block/lib/Drupal/block/BlockPluginEvents.php @@ -17,7 +17,7 @@ class BlockPluginEvents { * * This could be the case, when something is disabled but not deleted. */ - const TEMPORARILY_UNAVAILABLE = 'temporary'; + const TEMPORARILY_UNAVAILABLE = 'block.unavailable.temporarily'; /** * This event is thrown when a block plugin is permanently unavailable. @@ -25,6 +25,6 @@ class BlockPluginEvents { * This could be the case, when a module has been uninstalled or the data * from which a block plugin was derived was deleted. */ - const PERMANENTLY_UNAVAILABLE = 'permanent'; + const PERMANENTLY_UNAVAILABLE = 'block.unavailable.permanently'; }