You are here

public function MediaRevisionDeleteForm::submitForm in Media Revisions UI 8

Same name and namespace in other branches
  1. 2.0.x src/Form/MediaRevisionDeleteForm.php \Drupal\media_revisions_ui\Form\MediaRevisionDeleteForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/MediaRevisionDeleteForm.php, line 110

Class

MediaRevisionDeleteForm
Provides a form for reverting media revision.

Namespace

Drupal\media_revisions_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $this->mediaStorage
    ->deleteRevision($this->revision
    ->getRevisionId());
  $this
    ->logger('content')
    ->notice('@type: deleted %title revision %revision.', [
    '@type' => $this->revision
      ->bundle(),
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Revision from %revision-date of %title has been deleted.', [
    '%revision-date' => $this->dateFormatter
      ->format($this->revision
      ->getRevisionCreationTime()),
    '%title' => $this->revision
      ->label(),
  ]));
  $form_state
    ->setRedirect('entity.media.canonical', [
    'media' => $this->revision
      ->id(),
  ]);
  $revisionCount = $this->mediaStorage
    ->getQuery()
    ->allRevisions()
    ->condition('mid', $this->revision
    ->id())
    ->count()
    ->execute();
  if ($revisionCount > 1) {
    $form_state
      ->setRedirect('entity.media.version_history', [
      'media' => $this->revision
        ->id(),
    ]);
  }
}