public function ConfirmAddForm::submitForm in Simplenews 8
Same name and namespace in other branches
- 8.2 src/Form/ConfirmAddForm.php \Drupal\simplenews\Form\ConfirmAddForm::submitForm()
- 3.x src/Form/ConfirmAddForm.php \Drupal\simplenews\Form\ConfirmAddForm::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/ ConfirmAddForm.php, line 79
Class
- ConfirmAddForm
- Implements a add confirmation form for simplenews subscriptions.
Namespace
Drupal\simplenews\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
\Drupal::service('simplenews.subscription_manager')
->subscribe($form_state
->getValue('mail'), $form_state
->getValue('newsletter')
->id(), FALSE, 'website');
$config = \Drupal::config('simplenews.settings');
if ($path = $config
->get('subscription.confirm_subscribe_page')) {
$form_state
->setRedirectUrl(Url::fromUri("internal:{$path}"));
}
else {
$this
->messenger()
->addMessage(t('%user was added to the %newsletter mailing list.', array(
'%user' => $form_state
->getValue('mail'),
'%newsletter' => $form_state
->getValue('newsletter')->name,
)));
$form_state
->setRedirect('<front>');
}
}