Commit 2441134b authored by larowlan's avatar larowlan

Issue #2851225 by Sam152, Gábor Hojtsy: Ensure non-configuration bundles are...

Issue #2851225 by Sam152, Gábor Hojtsy: Ensure non-configuration bundles are correctly removed when the bundles go away
parent 5ea0e3ae
......@@ -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().
*/
......
......@@ -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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment