File tree Expand file tree Collapse file tree 2 files changed +29
-4
lines changed
modules/content_moderation Expand file tree Collapse file tree 2 files changed +29
-4
lines changed Original file line number Diff line number Diff 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 ());
Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments