Issue #3003238 by Sam152, amateescu, Berdir: EntityStorageException: Default revision can not be deleted in content_moderation_entity_revision_delete()
parent
94ac341ed9
commit
2492cdda1c
|
@ -235,10 +235,11 @@ class EntityOperations implements ContainerInjectionInterface {
|
||||||
* @see hook_entity_revision_delete()
|
* @see hook_entity_revision_delete()
|
||||||
*/
|
*/
|
||||||
public function entityRevisionDelete(EntityInterface $entity) {
|
public function entityRevisionDelete(EntityInterface $entity) {
|
||||||
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
|
if ($content_moderation_state = ContentModerationStateEntity::loadFromModeratedEntity($entity)) {
|
||||||
if (!$entity->isDefaultRevision()) {
|
if ($content_moderation_state->isDefaultRevision()) {
|
||||||
$content_moderation_state = ContentModerationStateEntity::loadFromModeratedEntity($entity);
|
$content_moderation_state->delete();
|
||||||
if ($content_moderation_state) {
|
}
|
||||||
|
else {
|
||||||
$this->entityTypeManager
|
$this->entityTypeManager
|
||||||
->getStorage('content_moderation_state')
|
->getStorage('content_moderation_state')
|
||||||
->deleteRevision($content_moderation_state->getRevisionId());
|
->deleteRevision($content_moderation_state->getRevisionId());
|
||||||
|
|
|
@ -238,6 +238,30 @@ class ContentModerationStateTest extends KernelTestBase {
|
||||||
$this->assertFalse($content_moderation_state);
|
$this->assertFalse($content_moderation_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests removal of content moderation state entities for preexisting content.
|
||||||
|
*/
|
||||||
|
public function testExistingContentModerationStateDataRemoval() {
|
||||||
|
$storage = $this->entityTypeManager->getStorage('entity_test_mulrevpub');
|
||||||
|
|
||||||
|
$entity = $storage->create([]);
|
||||||
|
$entity->save();
|
||||||
|
$original_revision_id = $entity->getRevisionId();
|
||||||
|
|
||||||
|
$workflow = $this->createEditorialWorkflow();
|
||||||
|
$workflow->getTypePlugin()->addEntityTypeAndBundle($entity->getEntityTypeId(), $entity->bundle());
|
||||||
|
$workflow->save();
|
||||||
|
|
||||||
|
$entity->moderation_state = 'draft';
|
||||||
|
$entity->save();
|
||||||
|
|
||||||
|
$storage->deleteRevision($entity->getRevisionId());
|
||||||
|
|
||||||
|
$entity = $this->reloadEntity($entity);
|
||||||
|
$this->assertEquals('published', $entity->moderation_state->value);
|
||||||
|
$this->assertEquals($original_revision_id, $storage->getLatestRevisionId($entity->id()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests removal of content moderation state translations.
|
* Tests removal of content moderation state translations.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue