Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / entity_reference_revisions / src / Plugin / Field / FieldType / EntityReferenceRevisionsItem.php
index 0242d981e98317ee53793d9a6f41db15ec266b59..cdf2867b1b389046f0c2ea54a20fdfadda0b875e 100644 (file)
@@ -323,6 +323,31 @@ class EntityReferenceRevisionsItem extends EntityReferenceItem implements Option
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function deleteRevision() {
+    $child = $this->entity;
+    if ($child->isDefaultRevision()) {
+      // Do not delete if it is the default revision.
+      return;
+    }
+
+    $host = $this->getEntity();
+    $field_name = $this->getFieldDefinition()->getName() . '.target_revision_id';
+    $all_revisions = \Drupal::entityQuery($host->getEntityTypeId())
+      ->condition($field_name, $child->getRevisionId())
+      ->allRevisions()
+      ->execute();
+
+    if (count($all_revisions) > 1) {
+      // Do not delete if there is more than one usage of this revision.
+      return;
+    }
+
+    \Drupal::entityTypeManager()->getStorage($child->getEntityTypeId())->deleteRevision($child->getRevisionId());
+  }
+
   /**
    * {@inheritdoc}
    */