Commit 191bf528 authored by catch's avatar catch

Issue #2848089 by Sam152, mpotter, gnuget, kriboogh, joelpittet: Unable to set...

Issue #2848089 by Sam152, mpotter, gnuget, kriboogh, joelpittet: Unable to set a moderation_state value for unsaved entities that are assigned an ID
parent 679fe1f1
......@@ -175,6 +175,10 @@ public function isLiveRevision(ContentEntityInterface $entity) {
public function isDefaultRevisionPublished(ContentEntityInterface $entity) {
$workflow = $this->getWorkflowForEntity($entity);
$default_revision = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->load($entity->id());
// If no default revision could be loaded, the entity has not yet been
// saved. In this case the moderation_state of the unsaved entity can be
// used, since once saved it will become the default.
$default_revision = $default_revision ?: $entity;
// Ensure we are checking all translations of the default revision.
if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) {
......
......@@ -251,4 +251,34 @@ public function entityUnserializeTestCases() {
];
}
/**
* Test saving a moderated node with an existing ID.
*
* @dataProvider moderatedEntityWithExistingIdTestCases
*/
public function testModeratedEntityWithExistingId($state) {
$node = Node::create([
'title' => 'Test title',
'type' => 'example',
'nid' => 999,
'moderation_state' => $state,
]);
$node->save();
$this->assertEquals($state, $node->moderation_state->value);
}
/**
* Test cases for ::testModeratedEntityWithExistingId.
*/
public function moderatedEntityWithExistingIdTestCases() {
return [
'Draft non-default state' => [
'draft',
],
'Published default state' => [
'published',
],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment