diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module index 921fe2a0c592c2ad75597e047bb7ae50ca524c25..b67fbd3dfc60f6a1573204e020ada4b4418e0b6d 100644 --- a/core/modules/content_moderation/content_moderation.module +++ b/core/modules/content_moderation/content_moderation.module @@ -231,6 +231,20 @@ function content_moderation_entity_bundle_info_alter(&$bundles) { } } +/** + * Implements hook_entity_bundle_delete(). + */ +function content_moderation_entity_bundle_delete($entity_type_id, $bundle_id) { + // Remove non-configuration based bundles from content moderation based + // workflows when they are removed. + foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) { + if ($workflow->getTypePlugin()->appliesToEntityTypeAndBundle($entity_type_id, $bundle_id)) { + $workflow->getTypePlugin()->removeEntityTypeAndBundle($entity_type_id, $bundle_id); + $workflow->save(); + } + } +} + /** * Implements hook_ENTITY_TYPE_insert(). */ diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 5fe22adb8eb379b9ad9f0c12acce8325311ae16d..55173dd270440c1cf67c6f5759903c2cf306ee9b 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -461,6 +461,41 @@ public function testWorkflowDependencies() { $this->assertEquals([], $entity_types); } + /** + * Test the content moderation workflow dependencies for non-config bundles. + */ + public function testWorkflowNonConfigBundleDependencies() { + // Create a bundle not based on any particular configuration. + entity_test_create_bundle('test_bundle'); + + $workflow = Workflow::load('editorial'); + $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test', 'test_bundle'); + $workflow->save(); + + // Ensure the bundle is correctly added to the workflow. + $this->assertEquals([ + 'module' => [ + 'content_moderation', + 'entity_test', + ], + ], $workflow->getDependencies()); + $this->assertEquals([ + 'test_bundle', + ], $workflow->getTypePlugin()->getBundlesForEntityType('entity_test')); + + // Delete the test bundle to ensure the workflow entity responds + // appropriately. + entity_test_delete_bundle('test_bundle'); + + $workflow = Workflow::load('editorial'); + $this->assertEquals([], $workflow->getTypePlugin()->getBundlesForEntityType('entity_test')); + $this->assertEquals([ + 'module' => [ + 'content_moderation', + ], + ], $workflow->getDependencies()); + } + /** * Reloads the entity after clearing the static cache. *