You are here

protected function MailEntity::buildBody in Simplenews 3.x

Same name and namespace in other branches
  1. 8.2 src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::buildBody()
  2. 8 src/Mail/MailEntity.php \Drupal\simplenews\Mail\MailEntity::buildBody()

Build the themed newsletter body.

Parameters

string|null $format: (Optional) Override the default format. Defaults to getFormat().

Return value

string The newsletter body.

1 call to MailEntity::buildBody()
MailEntity::getBodyWithFormat in src/Mail/MailEntity.php
Get the body with the requested format.

File

src/Mail/MailEntity.php, line 319

Class

MailEntity
Default mail class for entities.

Namespace

Drupal\simplenews\Mail

Code

protected function buildBody($format = NULL) {
  if (empty($format)) {
    $format = $this
      ->getFormat();
  }
  if ($cache = $this->cache
    ->get($this, 'build', 'body:' . $format)) {
    return $cache;
  }
  $body = $this
    ->build($format) + [
    '#theme' => 'simplenews_newsletter_body',
    '#newsletter' => $this
      ->getNewsletter(),
    '#language' => $this
      ->getLanguage(),
    '#simplenews_subscriber' => $this
      ->getSubscriber(),
    '#key' => $this
      ->getKey(),
    '#format' => $format,
  ];
  $markup = \Drupal::service('renderer')
    ->renderPlain($body);
  $this->cache
    ->set($this, 'build', 'body:' . $format, $markup);
  return $markup;
}