Skip to content

Commit 8876ac9

Browse files
author
Nathaniel Catchpole
committed
Issue #3003238 by Sam152, amateescu, Berdir: EntityStorageException: Default revision can not be deleted in content_moderation_entity_revision_delete()
(cherry picked from commit 2492cdd)
1 parent 871eb5c commit 8876ac9

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

modules/content_moderation/src/EntityOperations.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,11 @@ public function entityDelete(EntityInterface $entity) {
235235
* @see hook_entity_revision_delete()
236236
*/
237237
public function entityRevisionDelete(EntityInterface $entity) {
238-
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
239-
if (!$entity->isDefaultRevision()) {
240-
$content_moderation_state = ContentModerationStateEntity::loadFromModeratedEntity($entity);
241-
if ($content_moderation_state) {
238+
if ($content_moderation_state = ContentModerationStateEntity::loadFromModeratedEntity($entity)) {
239+
if ($content_moderation_state->isDefaultRevision()) {
240+
$content_moderation_state->delete();
241+
}
242+
else {
242243
$this->entityTypeManager
243244
->getStorage('content_moderation_state')
244245
->deleteRevision($content_moderation_state->getRevisionId());

modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ public function testContentModerationStatePendingRevisionDataRemoval($entity_typ
238238
$this->assertFalse($content_moderation_state);
239239
}
240240

241+
/**
242+
* Tests removal of content moderation state entities for preexisting content.
243+
*/
244+
public function testExistingContentModerationStateDataRemoval() {
245+
$storage = $this->entityTypeManager->getStorage('entity_test_mulrevpub');
246+
247+
$entity = $storage->create([]);
248+
$entity->save();
249+
$original_revision_id = $entity->getRevisionId();
250+
251+
$workflow = $this->createEditorialWorkflow();
252+
$workflow->getTypePlugin()->addEntityTypeAndBundle($entity->getEntityTypeId(), $entity->bundle());
253+
$workflow->save();
254+
255+
$entity->moderation_state = 'draft';
256+
$entity->save();
257+
258+
$storage->deleteRevision($entity->getRevisionId());
259+
260+
$entity = $this->reloadEntity($entity);
261+
$this->assertEquals('published', $entity->moderation_state->value);
262+
$this->assertEquals($original_revision_id, $storage->getLatestRevisionId($entity->id()));
263+
}
264+
241265
/**
242266
* Tests removal of content moderation state translations.
243267
*

0 commit comments

Comments
 (0)