Skip to content

Instantly share code, notes, and snippets.

@flocondetoile
Created July 21, 2017 15:12
Show Gist options
  • Save flocondetoile/e4e45bfaec22f12b2233aef9b26c0823 to your computer and use it in GitHub Desktop.
Save flocondetoile/e4e45bfaec22f12b2233aef9b26c0823 to your computer and use it in GitHub Desktop.
/**
* Massages the message body into the format expected for rendering.
*
* @param array $message
* The message.
*
* @return array
*/
public function cleanBody(array $message) {
// Get default mail line endings and merge all lines in the e-mail body
// separated by the mail line endings. Keep Markup objects and escape others
// and then treat the result as safe markup.
$line_endings = Settings::get('mail_line_endings', PHP_EOL);
$message['body'] = Markup::create(implode($line_endings, array_map(function ($body) {
// If $item is not marked safe then it will be escaped.
return $body instanceOf MarkupInterface ? $body : Html::escape($body);
}, $message['body'])));
return $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment