You are here

public function DevelMailLog::format in Devel 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Mail/DevelMailLog.php \Drupal\devel\Plugin\Mail\DevelMailLog::format()
  2. 8 src/Plugin/Mail/DevelMailLog.php \Drupal\devel\Plugin\Mail\DevelMailLog::format()
  3. 4.x src/Plugin/Mail/DevelMailLog.php \Drupal\devel\Plugin\Mail\DevelMailLog::format()

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:

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/DevelMailLog.php, line 103

Class

DevelMailLog
Defines a mail backend that saves emails as temporary files.

Namespace

Drupal\devel\Plugin\Mail

Code

public function format(array $message) {

  // Join the body array into one string.
  $message['body'] = implode("\n\n", $message['body']);

  // Convert any HTML to plain-text.
  $message['body'] = MailFormatHelper::htmlToText($message['body']);

  // Wrap the mail body for sending.
  $message['body'] = MailFormatHelper::wrapMail($message['body']);
  return $message;
}