diff options
author | Lee Rowlands | 2017-07-15 08:24:38 (GMT) |
---|---|---|
committer | Lee Rowlands | 2017-07-15 08:24:38 (GMT) |
commit | 2441134b047d3c73a8c9fb0a692bfb6b75b514e5 (patch) | |
tree | d44125b4c161430cfb890aa87724b8a39fa08108 | |
parent | 5ea0e3ae8db073ec0d0e18244c0dedfa7107776c (diff) |
Issue #2851225 by Sam152, Gábor Hojtsy: Ensure non-configuration bundles are correctly removed when the bundles go away
-rw-r--r-- | core/modules/content_moderation/content_moderation.module | 14 | ||||
-rw-r--r-- | core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php | 35 |
2 files changed, 49 insertions, 0 deletions
diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module index 921fe2a..b67fbd3 100644 --- a/core/modules/content_moderation/content_moderation.module +++ b/core/modules/content_moderation/content_moderation.module @@ -232,6 +232,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(). */ function content_moderation_workflow_insert(WorkflowInterface $entity) { diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 5fe22ad..55173dd 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -462,6 +462,41 @@ class ContentModerationStateTest extends KernelTestBase { } /** + * 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. * * @param \Drupal\Core\Entity\EntityInterface $entity |