public function PetPreviewForm::submitForm in Previewable email templates 8.3
Same name and namespace in other branches
- 8.4 src/Form/PetPreviewForm.php \Drupal\pet\Form\PetPreviewForm::submitForm()
- 8 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 281
Class
- PetPreviewForm
- PetPreviewForm.
Namespace
Drupal\pet\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$storage = $form_state
->getStorage();
$values = $form_state
->getValues();
switch ($storage['step']) {
case 1:
$form_state
->setRebuild(TRUE);
$storage['recipients_array'] = $values['recipients_array'];
$storage['recipients'] = $values['recipients'];
$storage['subject'] = $values['subject'];
$storage['body'] = isset($values['body']) ? $values['body'] : NULL;
$storage['body_html'] = isset($values['body_html']) ? $values['body_html'] : NULL;
$storage['send_plain'] = isset($values['send_plain']) ? $values['send_plain'] : NULL;
$storage['reply_to'] = $values['reply_to'];
$storage['cc'] = $values['cc'];
$storage['bcc'] = $values['bcc'];
$form_state
->setStorage($storage);
$this
->makePreview($form_state);
$storage = $form_state
->getStorage();
break;
case 2:
$form_state
->setRebuild(TRUE);
$recipients = array_keys($storage['recipients_array']);
/** @var \Drupal\pet\Entity\PetInterface $pet */
$pet = $storage['pet'];
$pet
->setSubject($storage['subject']);
if (PetHelper::hasMimeMail() && !empty($storage['body'])) {
// Let Mime Mail create final plain text version.
$pet
->setBody($storage['body']);
}
$pet
->setBodyHtml($storage['body_html']['value']);
$pet
->setSendPlain($storage['send_plain']);
$pet
->setReplyTo($storage['reply_to']);
$pet
->setCc($storage['cc']);
$pet
->setBcc($storage['bcc']);
$pet
->sendMail($recipients, []);
$storage['step'] = 1;
drupal_set_message($this
->t('Email(s) sent'));
break;
}
$storage['step']++;
$form_state
->setStorage($storage);
}