protected function MailEntity::getBodyWithFormat in Simplenews 8
Same name and namespace in other branches
- 8.2 src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::getBodyWithFormat()
- 3.x src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::getBodyWithFormat()
Get the body with the requested format.
Parameters
string $format: Either html or plain.
Return value
string The rendered mail body as a string.
2 calls to MailEntity::getBodyWithFormat()
- MailEntity::getBody in src/
Mail/ MailEntity.php - Returns the mail body.
- MailEntity::getPlainBody in src/
Mail/ MailEntity.php - Returns the plaintext body.
File
- src/
Mail/ MailEntity.php, line 379
Class
- MailEntity
- Default mail class for entities.
Namespace
Drupal\simplenews\MailCode
protected function getBodyWithFormat($format) {
// Switch to correct user and language context.
$this
->setContext();
if ($cache = $this->cache
->get($this, 'final', 'body:' . $format)) {
return $cache;
}
$body = $this
->buildBody($format);
// Build message body, replace tokens.
$body = \Drupal::token()
->replace($body, $this
->getTokenContext(), array(
'langcode' => $this
->getLanguage(),
));
if ($format == 'plain') {
// Convert HTML to text if requested to do so.
$body = MailFormatHelper::htmlToText($body, $this
->getNewsletter()->hyperlinks);
}
else {
$body = Markup::create($body);
}
$this->cache
->set($this, 'final', 'body:' . $format, $body);
$this
->resetContext();
return $body;
}