You are here

public function EmailConfirmation::cancel in Email confirmer 8

Cancel the email confirmation.

Throws

\Drupal\email_confirmer\InvalidConfirmationStateException If confirmation is expired, confirmed or already cancelled.

Overrides EmailConfirmationInterface::cancel

File

src/Entity/EmailConfirmation.php, line 296

Class

EmailConfirmation
Defines the email confirmation entity class.

Namespace

Drupal\email_confirmer\Entity

Code

public function cancel() {
  $status = $this
    ->getStatus();
  if ($status != 'pending') {
    throw new InvalidConfirmationStateException('Unable to cancel ' . $status . ' confirmations.');
  }
  $this
    ->get('status')
    ->setValue(EmailConfirmationInterface::CANCELLED);

  // Invoke email_confirmer hook.
  \Drupal::moduleHandler()
    ->invokeAll('email_confirmer', [
    'cancel',
    $this,
  ]);
}