function OneTimeAuthentication::tokens

Same name and namespace in other branches
  1. main core/modules/user/src/OneTimeAuthentication.php \Drupal\user\OneTimeAuthentication::tokens()

Token callback to add unsafe tokens for user notifications.

This function is used by \Drupal\Core\Utility\Token::replace() to set up some additional tokens that can be used in notifications generated by user_mail().

@internal

Parameters

array $replacements: An associative array variable containing mappings from token names to values (for use with strtr()).

array $data: An associative array of token replacement values. If the 'user' element exists, it must contain a user account.

array $options: A keyed array of settings and flags to control the token replacement process. See \Drupal\Core\Utility\Token::replace().

\Drupal\Core\Render\BubbleableMetadata $bubbleableMetadata: Target for adding metadata.

File

core/modules/user/src/OneTimeAuthentication.php, line 164

Class

OneTimeAuthentication
Generate and verify one time authentication codes.

Namespace

Drupal\user

Code

public function tokens(&$replacements, $data, $options, BubbleableMetadata $bubbleableMetadata) : void {
  if (isset($data['user'])) {
    $oneTimeLoginUrl = $this->generateOneTimeLoginUrl($data['user'], $options)
      ->toString(TRUE);
    $bubbleableMetadata->addCacheableDependency($oneTimeLoginUrl);
    $replacements['[user:one-time-login-url]'] = $oneTimeLoginUrl->getGeneratedUrl();
    $cancelConfirmUrl = $this->generateCancelConfirmUrl($data['user'], $options)
      ->toString(TRUE);
    $bubbleableMetadata->addCacheableDependency($cancelConfirmUrl);
    $replacements['[user:cancel-url]'] = $cancelConfirmUrl->getGeneratedUrl();
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.