You are here

protected static function PetPreviewForm::makePreview in Previewable email templates 8.3

Generate a preview of the tokenized email for the first in the list.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

1 call to PetPreviewForm::makePreview()
PetPreviewForm::submitForm in src/Form/PetPreviewForm.php
Form submission handler.

File

src/Form/PetPreviewForm.php, line 464

Class

PetPreviewForm
PetPreviewForm.

Namespace

Drupal\pet\Form

Code

protected static function makePreview(FormStateInterface &$form_state) {
  $values = $form_state
    ->getValues();
  $storage = $form_state
    ->getStorage();
  $first = reset($storage['recipients_array']);
  $uid = isset($first['uid']) ? $first['uid'] : 0;
  $substitutions = PetHelper::getSubstitutions([
    'uid' => $uid,
  ]);
  $token = \Drupal::token();
  $storage['subject_preview'] = $token
    ->replace($values['subject'], $substitutions);
  $storage['body_preview'] = $token
    ->replace($values['body'], $substitutions);
  if (PetHelper::hasMimeMail()) {
    $storage['body_preview_html'] = $token
      ->replace($values['body_html']['value'], $substitutions);
    $storage['body_preview_html'] = check_markup($storage['body_preview_html'], $values['body_html']['format']);

    // @see MimeMailFormatHelper::mimeMailHtmlBody()
    if (empty($storage['body_preview'])) {

      // @todo Remove once filter_xss() can handle direct descendant selectors in inline CSS.
      // @see http://drupal.org/node/1116930
      // @see http://drupal.org/node/370903
      $storage['body_preview'] = MailFormatHelper::htmlToText($storage['body_preview_html']);
    }
  }
  $form_state
    ->setStorage($storage);
}