public function SubscribeForm::submitForm in SendinBlue 8
Same name and namespace in other branches
- 8.2 src/Form/SubscribeForm.php \Drupal\sendinblue\Form\SubscribeForm::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/ SubscribeForm.php, line 254
Class
- SubscribeForm
- Subscribe form to signup SendinBlue newsletter.
Namespace
Drupal\sendinblue\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$signup = $this->entityTypeManager
->getStorage(SendinblueManager::SENDINBLUE_SIGNUP_ENTITY)
->load($this->signupIp);
$settings = !$signup->settings
->first() ? [] : $signup->settings
->first()
->getValue();
// Send confirm email.
$email = $form_state
->getValue([
'fields',
'EMAIL',
]);
$email_confirmation = $settings['subscription']['settings']['email_confirmation'];
if ($email_confirmation) {
$template_id = $settings['subscription']['settings']['template'];
$this->sendinblueManager
->sendEmail('confirm', $email, $template_id);
}
$this->messenger
->addMessage($settings['subscription']['messages']['success']);
if ($settings['subscription']['settings']['redirect_url'] != '') {
$form_state
->setRedirectUrl(Url::fromUri('internal:/' . $settings['subscription']['settings']['redirect_url']));
}
}