You are here

public function PetPreviewForm::pet_make_preview in Previewable email templates 8

Same name and namespace in other branches
  1. 8.4 src/Form/PetPreviewForm.php \Drupal\pet\Form\PetPreviewForm::pet_make_preview()

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

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

File

src/Form/PetPreviewForm.php, line 289

Class

PetPreviewForm

Namespace

Drupal\pet\Form

Code

public function pet_make_preview(FormStateInterface &$form_state) {
  $values = $form_state
    ->getValues();
  $storage = $form_state
    ->getStorage();
  $params = [
    'pet_uid' => is_array($storage['recipients']) ? $storage['recipients'][0]['uid'] : NULL,
    'pet_nid' => $storage['nid'],
  ];
  $subs = pet_substitutions($storage['pet'], $params);
  $token = \Drupal::token();
  $storage['subject_preview'] = $token
    ->replace($values['subject'], $subs);
  $storage['body_preview'] = $token
    ->replace(pet_isset_or($values['mail_body']['value']), $subs);
  $storage['body_preview_plain'] = $token
    ->replace(pet_isset_or($values['mail_body_plain']['value']), $subs);
  $form_state
    ->setStorage($storage);
}