public function MailgunMail::format in Mailgun 8
Formats a message prior to sending.
Allows to preprocess, format, and postprocess a mail message before it is passed to the sending system. The message body is received as an array of lines that are either strings or objects implementing \Drupal\Component\Render\MarkupInterface. It must be converted to the format expected by mail() which is a single string that can be either plain text or HTML. In the HTML case an alternate plain-text version can be returned in $message['plain'].
The conversion process consists of the following steps:
- If the output is HTML then convert any input line that is a string using \Drupal\Component\Utility\Html\Html::Escape().
- If the output is plain text then convert any input line that is markup using \Drupal\Core\Mail\MailFormatHelper::htmlToText().
- Join the input lines into a single string.
- Wrap long lines using \Drupal\Core\Mail\MailFormatHelper::wrapMail().
Parameters
array $message: A message array, as described in hook_mail_alter().
Return value
array The formatted $message.
Overrides MailInterface::format
See also
\Drupal\Core\Mail\MailManagerInterface
File
- src/
Plugin/ Mail/ MailgunMail.php, line 88
Class
- MailgunMail
- Default Mailgun mail system plugin.
Namespace
Drupal\mailgun\Plugin\MailCode
public function format(array $message) {
// Join the body array into one string.
if (is_array($message['body'])) {
$message['body'] = implode("\n\n", $message['body']);
}
// If text format is specified in settings, run the message through it.
$format = $this->mailgunConfig
->get('format_filter');
if (!empty($format)) {
$message['body'] = check_markup($message['body'], $format, $message['langcode']);
}
// Skip theme formatting if the message does not support HTML.
if (isset($message['params']['html']) && !$message['params']['html']) {
return $message;
}
// Wrap body with theme function.
if ($this->mailgunConfig
->get('use_theme')) {
$render = [
'#theme' => isset($message['params']['theme']) ? $message['params']['theme'] : 'mailgun',
'#message' => $message,
];
$message['body'] = $this->renderer
->renderPlain($render);
}
return $message;
}