diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index 4a416312eaee26858e5d89d77d72ae9c6a694c37..b80ccdda87822d9235f56c698b66e114fa3e543f 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -331,7 +331,7 @@ public function getConfiguration() { */ public function getInitialState(WorkflowInterface $workflow, $entity = NULL) { if ($entity instanceof EntityPublishedInterface) { - return $workflow->getState($entity->isPublished() ? 'published' : 'draft'); + return $workflow->getState($entity->isPublished() && !$entity->isNew() ? 'published' : 'draft'); } return parent::getInitialState($workflow); } diff --git a/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php b/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php index 0150d3c6e5f524c329937700aed7832c0864ca22..3db6a662ce266724314b47d38c6b04ab76ac8544 100644 --- a/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/InitialStateTest.php @@ -77,6 +77,12 @@ public function testInitialState() { $this->assertEquals('draft', $loaded_unpublished_node->moderation_state->value); $this->assertEquals('published', $loaded_published_node->moderation_state->value); $this->assertEquals('draft', $loaded_entity_test->moderation_state->value); + + $presave_node = Node::create([ + 'type' => 'example', + 'title' => 'Presave node', + ]); + $this->assertEquals('draft', $presave_node->moderation_state->value); } } diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php index 7e9a75c3f412e0d78dcf3afa062472edcf9dae68..5a2f6a0b325559275b9fb3740f098bcf28c63907 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php @@ -64,7 +64,8 @@ protected function setUp() { * Test the field item list when accessing an index. */ public function testArrayIndex() { - $this->assertEquals('published', $this->testNode->moderation_state[0]->value); + $this->assertFalse($this->testNode->isPublished()); + $this->assertEquals('draft', $this->testNode->moderation_state[0]->value); } /** @@ -75,7 +76,7 @@ public function testArrayIteration() { foreach ($this->testNode->moderation_state as $item) { $states[] = $item->value; } - $this->assertEquals(['published'], $states); + $this->assertEquals(['draft'], $states); } }