How to get one time URL when we are writing hook_mail_alter?
Question
My Question is already present here but the previously given answer for my question can applied to Drupal 7 and I can not use the same solution in Drupal 8.
I hope it is okay not put the same question once again.
Solution
Bingo! Found the Solution myself:
function custom_module_mail_alter(&$message) {
if (!empty($message['id']) && $message['id'] == 'user_password_reset') {
$token_service = \Drupal::token();
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$account = $message['params']['account'];
$one_time_url_token = '[user:one-time-login-url]';
$one_time_url = $token_service->replace($one_time_url_token, ['user' => $account], ['langcode' => $language_interface->getId(), 'callback' => 'user_mail_tokens', 'clear' => TRUE]);
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange