You are here

function template_preprocess_easy_email_inbox_preview_view in Easy Email 8

Same name and namespace in other branches
  1. 2.0.x easy_email.module \template_preprocess_easy_email_inbox_preview_view()

File

./easy_email.module, line 178
Contains easy_email.module.

Code

function template_preprocess_easy_email_inbox_preview_view(array &$variables) {

  /** @var \Drupal\easy_email\Entity\EasyEmailInterface $easy_email */
  $easy_email = $variables['easy_email'];
  $inbox_preview = $easy_email
    ->getInboxPreview();
  if (!$easy_email
    ->hasField('body_html') || empty($inbox_preview)) {
    $inbox_preview = NULL;
    $html_body = $easy_email
      ->getHtmlBody();
    if (!empty($html_body)) {
      $body = [
        '#type' => 'processed_text',
        '#text' => $html_body['value'],
        '#format' => $html_body['format'],
      ];
      $renderer = \Drupal::service('renderer');
      $inbox_preview = $renderer
        ->executeInRenderContext(new RenderContext(), function () use ($renderer, $body) {
        return $renderer
          ->render($body);
      });
    }
    if (empty($inbox_preview)) {
      $plain_body = $easy_email
        ->getPlainBody();
      if (!empty($plain_body)) {
        $body = [
          '#plain_text' => $plain_body,
        ];
        $renderer = \Drupal::service('renderer');
        $inbox_preview = $renderer
          ->executeInRenderContext(new RenderContext(), function () use ($renderer, $body) {
          return $renderer
            ->render($body);
        });
      }
    }
  }
  $variables['inbox_preview'] = strip_tags(html_entity_decode($inbox_preview));
  $variables['subject'] = $easy_email
    ->getSubject();
  $from = $easy_email
    ->getFromName();
  if (empty($from)) {
    $from = $easy_email
      ->getFromAddress();
  }
  if (empty($from)) {

    /** @var \Drupal\Core\Config\ImmutableConfig $site_config */
    $site_config = \Drupal::config('system.site');
    $from = $site_config
      ->get('name');
  }
  $variables['from_name'] = $from;
}