public function LibraryItemRevisionRevertForm::submitForm

File

paragraphs/modules/paragraphs_library/src/Form/LibraryItemRevisionRevertForm.php, line 102

Class

LibraryItemRevisionRevertForm

Namespace

Drupal\paragraphs_library\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $original_revision_timestamp = $this->revision
    ->getChangedTime();
  $this->revision = $this
    ->prepareRevertedRevision($this->revision);
  $this->revision->revision_log = $this
    ->t('Copy of the revision from %date.', [
    '%date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]);
  $this->revision
    ->setChangedTime($this->time
    ->getRequestTime());
  $this->revision
    ->save();
  $this->messenger
    ->addMessage($this
    ->t('%title has been reverted to the revision from %revision-date.', [
    '%title' => $this->revision
      ->label(),
    '%revision-date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]));
  $form_state
    ->setRedirect('entity.paragraphs_library_item.version_history', [
    'paragraphs_library_item' => $this->revision
      ->id(),
  ]);
}