You are here

public function AutosaveFormAlterTrait::autosaveFormRejectSubmit in Autosave Form 8

Form submission handler for rejecting autosaved states.

File

src/Form/AutosaveFormAlterTrait.php, line 134

Class

AutosaveFormAlterTrait
Provides a trait for common autosave form alterations.

Namespace

Drupal\autosave_form\Form

Code

public function autosaveFormRejectSubmit($form, FormStateInterface $form_state) {

  // As this processing might take some time we want to prevent that if the
  // connection is terminated the user input will be lost.
  ignore_user_abort(TRUE);

  // Mark the form state with a flag indicating an action for autosave has
  // been chosen.
  $form_state
    ->set('autosave_form_rejected', TRUE);

  // Cache the form state in order for the flag to be kept.
  $form_state
    ->setCached();

  // Purge the autosave states.
  $this
    ->purgeAllAutosavedStates($form_state, $this->currentUser
    ->id());
}