You are here

public function ScheduleRevisionRevertForm::submitForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Form/ScheduleRevisionRevertForm.php \Drupal\business_rules\Form\ScheduleRevisionRevertForm::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/ScheduleRevisionRevertForm.php, line 113

Class

ScheduleRevisionRevertForm
Provides a form for reverting a Schedule revision.

Namespace

Drupal\business_rules\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->revision_log = t('Copy of the revision from %date.', [
    '%date' => $this->dateFormatter
      ->format($original_revision_timestamp),
  ]);
  $this->revision
    ->save();
  $this
    ->logger('content')
    ->notice('Schedule: reverted %title revision %revision.', [
    '%title' => $this->revision
      ->label(),
    '%revision' => $this->revision
      ->getRevisionId(),
  ]);
  drupal_set_message(t('Schedule %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.business_rules_schedule.version_history', [
    'schedule' => $this->revision
      ->id(),
  ]);
}