function UserHooks::mail

Implements hook_mail().

File

core/modules/user/src/Hook/UserHooks.php, line 254

Class

UserHooks
Hook implementations for user.

Namespace

Drupal\user\Hook

Code

public function mail($key, &$message, $params) {
    $token_service = \Drupal::token();
    $language_manager = \Drupal::languageManager();
    $langcode = $message['langcode'];
    $variables = [
        'user' => $params['account'],
    ];
    $language = $language_manager->getLanguage($langcode);
    $original_language = $language_manager->getConfigOverrideLanguage();
    $language_manager->setConfigOverrideLanguage($language);
    $mail_config = \Drupal::config('user.mail');
    $token_options = [
        'langcode' => $langcode,
        'callback' => 'user_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);
}

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