Issue #2848089 by Sam152, mpotter, gnuget, kriboogh, joelpittet: Unable to set a moderation_state value for unsaved entities that are assigned an ID
parent
679fe1f111
commit
191bf52849
|
@ -175,6 +175,10 @@ class ModerationInformation implements ModerationInformationInterface {
|
||||||
public function isDefaultRevisionPublished(ContentEntityInterface $entity) {
|
public function isDefaultRevisionPublished(ContentEntityInterface $entity) {
|
||||||
$workflow = $this->getWorkflowForEntity($entity);
|
$workflow = $this->getWorkflowForEntity($entity);
|
||||||
$default_revision = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->load($entity->id());
|
$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.
|
// Ensure we are checking all translations of the default revision.
|
||||||
if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) {
|
if ($default_revision instanceof TranslatableInterface && $default_revision->isTranslatable()) {
|
||||||
|
|
|
@ -251,4 +251,34 @@ class ModerationStateFieldItemListTest extends KernelTestBase {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue