Commit eb8b64df authored by xjm's avatar xjm

Issue #2850601 by alexpott, xjm, timmillwood: ContentModeration workflow type...

Issue #2850601 by alexpott, xjm, timmillwood: ContentModeration workflow type plugin preserves numeric keys on sorting and not sorting entity types
parent a3c32ebb
......@@ -145,7 +145,8 @@ public function removeEntityTypeAndBundle($entity_type_id, $bundle_id) {
public function addEntityTypeAndBundle($entity_type_id, $bundle_id) {
if (!$this->appliesToEntityTypeAndBundle($entity_type_id, $bundle_id)) {
$this->configuration['entity_types'][$entity_type_id][] = $bundle_id;
natsort($this->configuration['entity_types'][$entity_type_id]);
sort($this->configuration['entity_types'][$entity_type_id]);
ksort($this->configuration['entity_types']);
}
}
......
......@@ -78,4 +78,27 @@ public function testAppliesToEntityTypeAndBundle() {
$this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
}
/**
* @covers ::addEntityTypeAndBundle
*/
public function testAddEntityTypeAndBundle() {
/** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $workflow_plugin */
$workflow_plugin = $this->workflow->getTypePlugin();
// The bundles are intentionally added in reverse alphabetical order.
$workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
$workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_article');
// Add another entity type that comes alphabetically before 'fake_node'.
$workflow_plugin->addEntityTypeAndBundle('fake_block', 'fake_custom');
// The entity type keys and bundle values should be sorted alphabetically.
// The bundle array index should not reflect the order in which they are
// added.
$this->assertSame(
['fake_block' => ['fake_custom'], 'fake_node' => ['fake_article', 'fake_page']],
$workflow_plugin->getConfiguration()['entity_types']
);
}
}
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