You are here

public function SubscriptionsFormBase::submitUnsubscribe in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Form/SubscriptionsFormBase.php \Drupal\simplenews\Form\SubscriptionsFormBase::submitUnsubscribe()

Submit callback that unsubscribes from selected newsletters.

Parameters

array $form: The form structure.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

File

src/Form/SubscriptionsFormBase.php, line 283

Class

SubscriptionsFormBase
Entity form for Subscriber with common routines.

Namespace

Drupal\simplenews\Form

Code

public function submitUnsubscribe(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\simplenews\Subscription\SubscriptionManagerInterface $subscription_manager */
  $subscription_manager = \Drupal::service('simplenews.subscription_manager');
  foreach ($this
    ->extractNewsletterIds($form_state, TRUE) as $newsletter_id) {
    $subscription_manager
      ->unsubscribe($this->entity
      ->getMail(), $newsletter_id, NULL, 'website');
  }
  $sent = $subscription_manager
    ->sendConfirmations();
  $this
    ->messenger()
    ->addMessage($this
    ->getSubmitMessage($form_state, static::SUBMIT_UNSUBSCRIBE, $sent));
}