You are here

public function EmailConfirmation::confirm in Email confirmer 8

Process the email confirmation.

Parameters

string $hash: The received hash.

Return value

bool TRUE if confirmation was successfully processed, FALSE on mistmach hash.

Throws

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

Overrides EmailConfirmationInterface::confirm

File

src/Entity/EmailConfirmation.php, line 277

Class

EmailConfirmation
Defines the email confirmation entity class.

Namespace

Drupal\email_confirmer\Entity

Code

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

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