You are here

public function ConfirmRemovalForm::submitForm in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Form/ConfirmRemovalForm.php \Drupal\simplenews\Form\ConfirmRemovalForm::submitForm()
  2. 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 79

Class

ConfirmRemovalForm
Implements a removal confirmation form for simplenews subscriptions.

Namespace

Drupal\simplenews\Form

Code

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_subscribe_page')) {
    $form_state
      ->setRedirectUrl(Url::fromUri("internal:{$path}"));
  }
  else {
    $this
      ->messenger()
      ->addMessage(t('%user was unsubscribed from the %newsletter mailing list.', array(
      '%user' => $form_state
        ->getValue('mail'),
      '%newsletter' => $form_state
        ->getValue('newsletter')->name,
    )));
    $form_state
      ->setRedirect('<front>');
  }
}