You are here

function social_auth_extra_mail in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  2. 8 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  3. 8.2 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  4. 8.3 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  5. 8.5 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  6. 8.6 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  7. 8.7 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()
  8. 8.8 modules/custom/social_auth_extra/social_auth_extra.module \social_auth_extra_mail()

Implements hook_mail().

File

modules/custom/social_auth_extra/social_auth_extra.module, line 440
Contains social_auth_extra.module.

Code

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