You are here

function content_moderation_notifications_mail in Content Moderation Notifications 8.3

Same name and namespace in other branches
  1. 8 content_moderation_notifications.module \content_moderation_notifications_mail()
  2. 8.2 content_moderation_notifications.module \content_moderation_notifications_mail()

Implements hook_mail().

File

./content_moderation_notifications.module, line 42
Hook implementations for the content moderation notifications module.

Code

function content_moderation_notifications_mail($key, &$message, $params) {
  switch ($key) {
    case 'content_moderation_notification':

      // Add headers, specifically this should include the Bcc header.
      if (!empty($params['headers'])) {
        foreach ($params['headers'] as $id => $value) {
          $message['headers'][$id] = $params['headers'][$id];
        }
      }
      $message['from'] = \Drupal::config('system.site')
        ->get('mail');
      $token_service = \Drupal::token();
      $context = $params['context'];
      $subject = PlainTextOutput::renderFromHtml($token_service
        ->replace($params['subject'], $context, [
        'clear' => TRUE,
      ]));
      $body = $token_service
        ->replace($params['message'], $context, [
        'clear' => TRUE,
      ]);
      $message['subject'] = str_replace([
        "\r",
        "\n",
      ], '', $subject);
      $message['body'][] = Markup::create($body);
      break;
  }
}