Issue #2971157 by jhedstrom, Sam152: Moderation state set to default after entity is serialized
parent
b989db1a3c
commit
ed9e93f52f
|
@ -141,11 +141,13 @@ class ModerationStateFieldItemList extends FieldItemList {
|
||||||
public function setValue($values, $notify = TRUE) {
|
public function setValue($values, $notify = TRUE) {
|
||||||
parent::setValue($values, $notify);
|
parent::setValue($values, $notify);
|
||||||
|
|
||||||
|
if (isset($this->list[0])) {
|
||||||
|
$this->valueComputed = TRUE;
|
||||||
|
}
|
||||||
// If the parent created a field item and if the parent should be notified
|
// 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),
|
// about the change (e.g. this is not initialized with the current value),
|
||||||
// update the moderated entity.
|
// update the moderated entity.
|
||||||
if (isset($this->list[0]) && $notify) {
|
if (isset($this->list[0]) && $notify) {
|
||||||
$this->valueComputed = TRUE;
|
|
||||||
$this->updateModeratedEntity($this->list[0]->value);
|
$this->updateModeratedEntity($this->list[0]->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,13 +211,39 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the moderation_state field after an entity has been serialized.
|
* Test the moderation_state field after an entity has been serialized.
|
||||||
|
*
|
||||||
|
* @dataProvider entityUnserializeTestCases
|
||||||
*/
|
*/
|
||||||
public function testEntityUnserialize() {
|
public function testEntityUnserialize($state, $default, $published) {
|
||||||
$this->testNode->moderation_state->value = 'draft';
|
$this->testNode->moderation_state->value = $state;
|
||||||
|
|
||||||
|
$this->assertEquals($state, $this->testNode->moderation_state->value);
|
||||||
|
$this->assertEquals($default, $this->testNode->isDefaultRevision());
|
||||||
|
$this->assertEquals($published, $this->testNode->isPublished());
|
||||||
|
|
||||||
$unserialized = unserialize(serialize($this->testNode));
|
$unserialized = unserialize(serialize($this->testNode));
|
||||||
|
|
||||||
$this->assertEquals('Test title', $unserialized->title->value);
|
$this->assertEquals($state, $unserialized->moderation_state->value);
|
||||||
$this->assertEquals('draft', $unserialized->moderation_state->value);
|
$this->assertEquals($default, $unserialized->isDefaultRevision());
|
||||||
|
$this->assertEquals($published, $unserialized->isPublished());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test cases for ::testEntityUnserialize.
|
||||||
|
*/
|
||||||
|
public function entityUnserializeTestCases() {
|
||||||
|
return [
|
||||||
|
'Default draft state' => [
|
||||||
|
'draft',
|
||||||
|
TRUE,
|
||||||
|
FALSE,
|
||||||
|
],
|
||||||
|
'Non-default published state' => [
|
||||||
|
'published',
|
||||||
|
TRUE,
|
||||||
|
TRUE,
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue