You are here

public function PetPreviewForm::submitForm in Previewable email templates 8

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

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

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

Overrides FormInterface::submitForm

File

src/Form/PetPreviewForm.php, line 244

Class

PetPreviewForm

Namespace

Drupal\pet\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $storage = $form_state
    ->getStorage();
  $step = empty($storage['step']) ? 1 : $storage['step'];
  $storage['step'] = $step;
  $values = $form_state
    ->getValues();
  switch ($step) {
    case 1:
      $form_state
        ->setRebuild(TRUE);
      $storage['recipients_raw'] = $values['recipients'];
      $storage['recipients'] = $values['recipients'];
      $storage['subject'] = $values['subject'];
      $storage['mail_body'] = pet_isset_or($values['mail_body']);
      $storage['mail_body_plain'] = pet_isset_or($values['mail_body_plain']);
      $storage['cc'] = $values['cc'];
      $storage['bcc'] = $values['bcc'];
      $form_state
        ->setStorage($storage);
      $this
        ->pet_make_preview($form_state);
      $storage = $form_state
        ->getStorage();
      break;
    case 2:
      $form_state
        ->setRebuild(TRUE);
      $pet = $storage['pet'];
      $recipients = $storage['recipients'];
      $options = [
        'nid' => $storage['nid'],
        'subject' => $storage['subject'],
        'body' => $storage['mail_body'],
        'body_plain' => $storage['mail_body_plain'],
        'from' => NULL,
        'cc' => $storage['cc'],
        'bcc' => $storage['bcc'],
      ];
      pet_send_mail($pet
        ->id(), $recipients, $options);
      break;
  }
  $storage['step']++;
  $form_state
    ->setStorage($storage);
}