You are here

public function HomeboxLayoutRevisionRevertForm::submitForm in Homebox 8

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/HomeboxLayoutRevisionRevertForm.php, line 131

Class

HomeboxLayoutRevisionRevertForm
Provides a form for reverting a Homebox Layout revision.

Namespace

Drupal\homebox\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // The revision timestamp will be updated when the revision is saved. Keep
  // the original one for the confirmation message.
  $original_revision_timestamp = $this->revision
    ->getRevisionCreationTime();
  $this->revision = $this
    ->prepareRevertedRevision($this->revision, $form_state);
  $this->revision
    ->setRevisionLogMessage(t('Copy of the revision from %date.', [
    '%date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]));
  $this->revision
    ->save();
  $this
    ->logger('content')
    ->notice('Homebox Layout: reverted %title revision %revision.', [
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  $this
    ->messenger()
    ->addMessage(t('Homebox Layout %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.homebox_layout.version_history', [
    'homebox_layout' => $this->revision
      ->id(),
  ]);
}