diff --git a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php index 1256bf27f4c83ad3413d647857caad8b53888abd..8d48f26ae4787933204a0a085f47abebb034e22e 100644 --- a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php +++ b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php @@ -141,7 +141,10 @@ public function onChange($delta) { public function setValue($values, $notify = TRUE) { parent::setValue($values, $notify); - if (isset($this->list[0])) { + // If the parent created a field item and if the parent should be notified + // about the change (e.g. this is not initialized with the current value), + // update the moderated entity. + if (isset($this->list[0]) && $notify) { $this->valueComputed = TRUE; $this->updateModeratedEntity($this->list[0]->value); } diff --git a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php index 7d95054f0c0c28648733baf8f9818fd6df9a3084..c4770166408cc93644ed4719fc8776503e0797e2 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php @@ -173,4 +173,15 @@ public function testEntityWithNoWorkflow() { $this->assertTrue($test_node->isPublished()); } + /** + * Test the moderation_state field after an entity has been serialized. + */ + public function testEntityUnserialize() { + $this->testNode->moderation_state->value = 'draft'; + $unserialized = unserialize(serialize($this->testNode)); + + $this->assertEquals('Test title', $unserialized->title->value); + $this->assertEquals('draft', $unserialized->moderation_state->value); + } + }