public function MandrillAdminTestForm::submitForm in Mandrill 8
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/ MandrillAdminTestForm.php, line 109
Class
- MandrillAdminTestForm
- Form controller for the Mandrill send test email form.
Namespace
Drupal\mandrill\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$message = array(
'id' => 'mandrill_test_email',
'module' => 'mandrill',
'to' => $form_state
->getValue('mandrill_test_address'),
'body' => $form_state
->getValue('mandrill_test_body'),
'subject' => $this
->t('Drupal Mandrill test email'),
);
$bcc_email = $form_state
->getValue('mandrill_test_bcc_address');
if (!empty($bcc_email)) {
$message['bcc_email'] = $bcc_email;
}
if ($form_state
->getValue('include_attachment')) {
$message['attachments'][] = \Drupal::service('file_system')
->realpath('core/themes/bartik/logo.svg');
$message['body'] .= ' ' . $this
->t('The Drupal icon is included as an attachment to test the attachment functionality.');
}
// Get Mandrill mailer service specified in Mailsystem settings.
// This service will either be mandrill_mail or mandrill_test_mail or the
// route that exposes this form won't even show up - see
// MandrillMailerAccessCheck.php.
$sender = \Drupal::config('mailsystem.settings')
->get('defaults')['sender'];
if ($sender == 'mandrill_mail') {
/* @var $mandrill \Drupal\mandrill\Plugin\Mail\MandrillMail */
$mailer = new MandrillMail();
}
elseif ($sender == 'mandrill_test_mail') {
/* @var $mandrill \Drupal\mandrill\Plugin\Mail\MandrillTestMail */
$mailer = new MandrillTestMail();
}
// Ensure we have a mailer and send the message.
if (isset($mailer) && $mailer
->mail($message)) {
$this
->messenger()
->addStatus($this
->t('Test email has been sent.'));
}
}