You are here

function email_confirmer_tokens in Email confirmer 8

Implements hook_tokens().

File

./email_confirmer.tokens.inc, line 42
Token related hook implementations.

Code

function email_confirmer_tokens($type, $tokens, $data, $options, BubbleableMetadata $bubbleable_metadata) {
  if ($type != 'email-confirmer' || !isset($data['email_confirmer_confirmation'])) {
    return [];
  }
  $replacements = [];

  /** @var \Drupal\email_confirmer\EmailConfirmationInterface $confirmation */
  $confirmation = $data['email_confirmer_confirmation'];
  foreach ($tokens as $name => $original) {
    switch ($name) {
      case 'confirmation-url':
        $replacements[$original] = Url::fromRoute('entity.email_confirmer_confirmation.response_form', [
          'email_confirmer_confirmation' => $confirmation
            ->uuid(),
          'hash' => $confirmation
            ->getHash(),
        ])
          ->setAbsolute()
          ->toString();
        $bubbleable_metadata
          ->setCacheMaxAge(0);
        break;
      case 'confirmation-mail':
        $replacements[$original] = $confirmation
          ->getEmail();
        break;
    }
  }
  return $replacements;
}