diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index c6822137cb8e599a260932127c0fd7e2a588c2ac..a5d040190e04a43f23636cff7e7c56cd60d6303e 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -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']); } } diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php index 5de2ced4856a11cab14aaf6404bcbc3760e74c70..c2ea8c576d514d106e5ba92f0778ff9e686af831 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationWorkflowTypeApiTest.php @@ -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'] + ); + } + }