public function SubscriptionsFormBase::submitExtra in Simplenews 3.x
Submit callback that (un)subscribes to newsletters based on selection.
Parameters
array $form: The form structure.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
1 method overrides SubscriptionsFormBase::submitExtra()
- SubscriptionsBlockForm::submitExtra in src/
Form/ SubscriptionsBlockForm.php - Submit callback that subscribes to selected newsletters.
File
- src/
Form/ SubscriptionsFormBase.php, line 153
Class
- SubscriptionsFormBase
- Entity form for Subscriber with common routines.
Namespace
Drupal\simplenews\FormCode
public function submitExtra(array $form, FormStateInterface $form_state) {
// We first subscribe, then unsubscribe. This prevents deletion of
// subscriptions when unsubscribed from the newsletter.
/** @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, FALSE, 'website');
}
if (!$this->entity
->isNew()) {
foreach ($this
->extractNewsletterIds($form_state, FALSE) as $newsletter_id) {
$subscription_manager
->unsubscribe($this->entity
->getMail(), $newsletter_id, FALSE, 'website');
}
}
$this
->messenger()
->addMessage($this
->getSubmitMessage($form_state, FALSE));
}