You are here

public function SubscriptionsFormBase::submitSubscribe in Simplenews 8

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

Submit callback that subscribes to selected newsletters.

Parameters

array $form: The form structure.

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

File

src/Form/SubscriptionsFormBase.php, line 265

Class

SubscriptionsFormBase
Entity form for Subscriber with common routines.

Namespace

Drupal\simplenews\Form

Code

public function submitSubscribe(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
      ->subscribe($this->entity
      ->getMail(), $newsletter_id, NULL, 'website');
  }
  $sent = $subscription_manager
    ->sendConfirmations();
  $this
    ->messenger()
    ->addMessage($this
    ->getSubmitMessage($form_state, static::SUBMIT_SUBSCRIBE, $sent));
}