You are here

public function MediaRevisionRevertForm::submitForm in Media Revisions UI 8

Same name and namespace in other branches
  1. 2.0.x src/Form/MediaRevisionRevertForm.php \Drupal\media_revisions_ui\Form\MediaRevisionRevertForm::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/MediaRevisionRevertForm.php, line 122

Class

MediaRevisionRevertForm
Provides a form for reverting media revision.

Namespace

Drupal\media_revisions_ui\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $originalRevisionTime = $this->revision
    ->getRevisionCreationTime();
  $this->revision = $this
    ->prepareRevertedRevision($this->revision, $form_state);
  $this->revision
    ->setRevisionLogMessage($this
    ->t('Copy of the revision from %date.', [
    '%date' => $this->dateFormatter
      ->format($originalRevisionTime),
  ]));
  $this->revision
    ->setRevisionUserId($this
    ->currentUser()
    ->id());
  $this->revision
    ->setRevisionCreationTime($this->time
    ->getRequestTime());
  $this->revision
    ->setChangedTime($this->time
    ->getRequestTime());
  $this->revision
    ->save();
  $this
    ->logger('content')
    ->notice('@type: reverted %title revision %revision.', [
    '@type' => $this->revision
      ->getEntityType()
      ->getLabel(),
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $this
    ->messenger()
    ->addStatus($this
    ->t('@type %title has been reverted to the revision from %revision-date.', [
    '@type' => $this->revision
      ->getEntityType()
      ->getLabel(),
    '%title' => $this->revision
      ->label(),
    '%revision-date' => $this->dateFormatter
      ->format($originalRevisionTime),
  ]));
  $form_state
    ->setRedirect('entity.media.version_history', [
    'media' => $this->revision
      ->id(),
  ]);
}