You are here

function user_registrationpassword_mail in User registration password 8

Same name and namespace in other branches
  1. 6 user_registrationpassword.module \user_registrationpassword_mail()
  2. 7 user_registrationpassword.module \user_registrationpassword_mail()

Implements hook_mail().

See also

drupal_mail()

user_mail()

File

./user_registrationpassword.module, line 310
Enables password creation on registration form.

Code

function user_registrationpassword_mail($key, &$message, $params) {
  $token_service = \Drupal::token();
  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];
  $variables = [
    'user' => $params['account'],
  ];
  $language = $language_manager
    ->getLanguage($params['account']
    ->getPreferredLangcode());
  $original_language = $language_manager
    ->getConfigOverrideLanguage();
  $language_manager
    ->setConfigOverrideLanguage($language);
  $mail_config = \Drupal::config('user_registrationpassword.mail');
  $token_options = [
    'langcode' => $langcode,
    'callback' => 'user_registrationpassword_mail_tokens',
    'clear' => TRUE,
  ];
  $message['subject'] .= PlainTextOutput::renderFromHtml($token_service
    ->replace($mail_config
    ->get($key . '.subject'), $variables, $token_options));
  $message['body'][] = $token_service
    ->replace($mail_config
    ->get($key . '.body'), $variables, $token_options);
  $language_manager
    ->setConfigOverrideLanguage($original_language);
}