public function EntityReferenceRevisionsItem::deleteRevision in Entity Reference Revisions 8
Defines custom revision delete behavior for field values.
This method is called from during the process of deleting an entity revision, just before the field values are deleted from storage. It is only called for entity types that support revisioning.
Overrides FieldItemBase::deleteRevision
File
- src/
Plugin/ Field/ FieldType/ EntityReferenceRevisionsItem.php, line 378
Class
- EntityReferenceRevisionsItem
- Defines the 'entity_reference_revisions' entity field type.
Namespace
Drupal\entity_reference_revisions\Plugin\Field\FieldTypeCode
public function deleteRevision() {
$child = $this->entity;
// Return early, and do not delete the child revision, when the child
// revision is either:
// 1: Missing.
// 2: A default revision.
if (!$child || $child
->isDefaultRevision()) {
return;
}
$host = $this
->getEntity();
$field_name = $this
->getFieldDefinition()
->getName() . '.target_revision_id';
$all_revisions = \Drupal::entityQuery($host
->getEntityTypeId())
->condition($field_name, $child
->getRevisionId())
->allRevisions()
->accessCheck(FALSE)
->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());
}