function RevisionDeleteForm::submitForm
Same name in other branches
- 11.x core/lib/Drupal/Core/Entity/Form/RevisionDeleteForm.php \Drupal\Core\Entity\Form\RevisionDeleteForm::submitForm()
Overrides FormInterface::submitForm
File
-
core/
lib/ Drupal/ Core/ Entity/ Form/ RevisionDeleteForm.php, line 141
Class
- RevisionDeleteForm
- Provides a form for deleting an entity revision.
Namespace
Drupal\Core\Entity\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$entityTypeId = $this->revision
->getEntityTypeId();
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $entityStorage */
$entityStorage = $this->entityTypeManager
->getStorage($entityTypeId);
$entityStorage->deleteRevision($this->revision
->getRevisionId());
$bundleLabel = $this->getBundleLabel($this->revision);
$messengerArgs = [
'@type' => $bundleLabel ?? $this->revision
->getEntityType()
->getLabel(),
'%title' => $this->revision
->label(),
];
if ($this->revision instanceof RevisionLogInterface) {
$messengerArgs['%revision-date'] = $this->dateFormatter
->format($this->revision
->getRevisionCreationTime());
$this->messenger
->addStatus($this->t('Revision from %revision-date of @type %title has been deleted.', $messengerArgs));
}
else {
$this->messenger
->addStatus($this->t('Revision of @type %title has been deleted.', $messengerArgs));
}
$this->logger($this->revision
->getEntityType()
->getProvider())
->info('@type: deleted %title revision %revision.', [
'@type' => $this->revision
->bundle(),
'%title' => $this->revision
->label(),
'%revision' => $this->revision
->getRevisionId(),
]);
// When there is one remaining revision or more, redirect to the version
// history page.
if ($this->revision
->hasLinkTemplate('version-history')) {
$query = $this->entityTypeManager
->getStorage($entityTypeId)
->getQuery();
$remainingRevisions = $query->accessCheck(FALSE)
->allRevisions()
->condition($this->revision
->getEntityType()
->getKey('id'), $this->revision
->id())
->count()
->execute();
$versionHistoryUrl = $this->revision
->toUrl('version-history');
if ($remainingRevisions && $versionHistoryUrl->access($this->currentUser())) {
$form_state->setRedirectUrl($versionHistoryUrl);
}
}
if (!$form_state->getRedirect()) {
$canonicalUrl = $this->revision
->toUrl();
if ($canonicalUrl->access($this->currentUser())) {
$form_state->setRedirectUrl($canonicalUrl);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.