You are here

public function SubscriptionsBlockForm::submitExtra in Simplenews 3.x

Submit callback that subscribes to selected newsletters.

Parameters

array $form: The form structure.

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

Overrides SubscriptionsFormBase::submitExtra

File

src/Form/SubscriptionsBlockForm.php, line 121

Class

SubscriptionsBlockForm
Add subscriptions for authenticated user or new subscriber.

Namespace

Drupal\simplenews\Form

Code

public function submitExtra(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, $sent));
}