function user_email_verification_tokens in User email verification 8
Same name and namespace in other branches
- 7 user_email_verification.tokens.inc \user_email_verification_tokens()
Implements hook_tokens().
File
- ./
user_email_verification.tokens.inc, line 31 - Builds placeholder replacement tokens for user-related data.
Code
function user_email_verification_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = [];
if ($type == 'user' && isset($data['user']) && $data['user'] instanceof UserInterface) {
/** @var \Drupal\user_email_verification\UserEmailVerificationInterface $service */
$service = \Drupal::service('user_email_verification.service');
foreach ($tokens as $name => $original) {
switch ($name) {
case 'verify-email':
$replacements[$original] = $service
->buildVerificationUrl($data['user'])
->toString();
break;
case 'verify-email-extended':
$replacements[$original] = $service
->buildExtendedVerificationUrl($data['user'])
->toString();
break;
}
}
}
return $replacements;
}