You are here

public function EmailConfirmerManager::confirm in Email confirmer 8

Starts an email confirmation process.

Existing confirmation for the given email address will be used if it is in pending status, otherwise a new one will be created. Confirmation request email is sent by this method.

Parameters

string $email: Email address to be confirmed.

array $data: An optional property map to store with the confirmation.

string $realm: A realm to which this confirmation belongs. Tipically, a module name.

Return value

\Drupal\email_confirmer\EmailConfirmationInterface The email confirmation entity.

Overrides EmailConfirmerManagerInterface::confirm

File

src/EmailConfirmerManager.php, line 54

Class

EmailConfirmerManager
Email confirmation service.

Namespace

Drupal\email_confirmer

Code

public function confirm($email, array $data = [], $realm = '') {
  $confirmation = $this
    ->getConfirmation($email, 'pending', $realm);
  if (!$confirmation) {
    $confirmation = $this
      ->createConfirmation($email);
  }

  // Set the realm.
  if (!empty($realm)) {
    $confirmation
      ->setRealm($realm);
  }

  // Store properties.
  foreach ($data as $key => $value) {
    $confirmation
      ->setProperty($key, $value);
  }
  $confirmation
    ->sendRequest();
  $confirmation
    ->save();
  return $confirmation;
}