From eb8b64df0fde0052e5689b7adc66d92e19a029e9 Mon Sep 17 00:00:00 2001 From: xjm Date: Wed, 8 Feb 2017 15:48:58 -0600 Subject: [PATCH] Issue #2850601 by alexpott, xjm, timmillwood: ContentModeration workflow type plugin preserves numeric keys on sorting and not sorting entity types --- .../Plugin/WorkflowType/ContentModeration.php | 3 ++- .../ContentModerationWorkflowTypeApiTest.php | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index c6822137cb..a5d040190e 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 5de2ced485..c2ea8c576d 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'] + ); + } + } -- GitLab