You are here

public function UserEmailChangeCancelForm::submitForm in Email confirmer 8

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

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 ContentEntityForm::submitForm

File

email_confirmer_user/src/Form/UserEmailChangeCancelForm.php, line 109

Class

UserEmailChangeCancelForm
User pending email change cancellation form.

Namespace

Drupal\email_confirmer_user\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $new_email = $this->userData
    ->get('email_confirmer_user', $this->entity
    ->id(), 'email_change_new_address');
  $this->userData
    ->delete('email_confirmer_user', $this->entity
    ->id(), 'email_change_new_address');

  // The confirmation cancel URL.
  $cancel_url = NULL;

  // Cancel any pending address confirmation for the requested new email.

  /** @var \Drupal\email_confirmer\EmailConfirmationInterface $confirmation */
  foreach ($this->emailConfirmer
    ->getConfirmations($new_email, 'pending', 0, 'email_confirmer_user') as $confirmation) {
    $confirmation
      ->cancel();
    $confirmation
      ->save();
    $cancel_url = $confirmation
      ->getResponseUrl('cancel');
  }

  // Go to the (last) confirmation cancel URL, the user edit form otherwise.
  $form_state
    ->setRedirectUrl($cancel_url ?: $this->entity
    ->toUrl('edit-form'));
}