You are here

function apigee_edge_mail in Apigee Edge 8

Implements hook_mail().

Based on user_mail().

File

./apigee_edge.module, line 607
Copyright 2018 Google Inc.

Code

function apigee_edge_mail($key, &$message, $params) {
  $token_service = \Drupal::token();
  $language_manager = \Drupal::languageManager();
  $langcode = $message['langcode'];

  /** @var \Drupal\Core\Session\AccountInterface $account */
  $account = $params['account'];
  $variables = [
    'user' => $account,
  ];
  $language = $language_manager
    ->getLanguage($account
    ->getPreferredLangcode());
  $original_language = $language_manager
    ->getConfigOverrideLanguage();
  $language_manager
    ->setConfigOverrideLanguage($language);
  $config = \Drupal::config('apigee_edge.developer_settings');
  $token_options = [
    'langcode' => $langcode,
    'callback' => '_apigee_edge_existing_developer_mail_tokens',
    'clear' => TRUE,
  ];
  $message['subject'] .= PlainTextOutput::renderFromHtml($token_service
    ->replace($config
    ->get('verification_email.subject'), $variables, $token_options));
  $message['body'][] = $token_service
    ->replace($config
    ->get('verification_email.body'), $variables, $token_options);
  $language_manager
    ->setConfigOverrideLanguage($original_language);
}