public function EntityReferenceRevisionsOrphanPurger::deleteUnusedRevision in Entity Reference Revisions 8
Deletes unused revision or an entity if there are no revisions remaining.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $composite_revision: The composite revision.
Return value
bool TRUE if an entity revision was deleted. Otherwise, FALSE.
1 call to EntityReferenceRevisionsOrphanPurger::deleteUnusedRevision()
- EntityReferenceRevisionsOrphanPurger::deleteOrphansBatchOperation in src/
EntityReferenceRevisionsOrphanPurger.php - Batch operation for checking orphans for a given entity type.
File
- src/
EntityReferenceRevisionsOrphanPurger.php, line 120
Class
- EntityReferenceRevisionsOrphanPurger
- Manages orphan composite revision deletion.
Namespace
Drupal\entity_reference_revisionsCode
public function deleteUnusedRevision(ContentEntityInterface $composite_revision) {
// If this is the default revision of the composite entity, check if there
// are other revisions. If there are not, delete the composite entity.
$composite_storage = $this->entityTypeManager
->getStorage($composite_revision
->getEntityTypeId());
if ($composite_revision
->isDefaultRevision()) {
$count = $composite_storage
->getQuery()
->accessCheck(FALSE)
->allRevisions()
->condition($composite_storage
->getEntityType()
->getKey('id'), $composite_revision
->id())
->count()
->execute();
if ($count <= 1) {
$composite_revision
->delete();
return TRUE;
}
}
else {
// Delete the revision if this is not the default one.
$composite_storage
->deleteRevision($composite_revision
->getRevisionId());
return TRUE;
}
return FALSE;
}