summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2018-02-27 22:46:58 (GMT)
committerAlex Pott2018-02-27 22:46:58 (GMT)
commit86746fce082a6d845a585933bce1a85ebd2d24a3 (patch)
treea8c0cb24c28a9d420cbfc98058a00a58ab817917
parent21dd26383579deec77298abd833f09f38bae0a81 (diff)
Issue #2940513 by Sam152, Berdir: ModerationStateFieldItemList fails after an entity has been serialized/unserialized
-rw-r--r--core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php5
-rw-r--r--core/modules/content_moderation/tests/src/Kernel/ModerationStateFieldItemListTest.php11
2 files changed, 15 insertions, 1 deletions
diff --git a/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php b/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php
index 1256bf2..8d48f26 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 @@ class ModerationStateFieldItemList extends FieldItemList {
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 7d95054..c477016 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 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
$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);
+ }
+
}