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