/**
  * Returns the newsletters available to select from.
  *
  * @return \Drupal\simplenews\Entity\Newsletter[]
  *   The newsletters available to select from, indexed by ID.
  */
 public function getNewsletters()
 {
     if (!isset($this->newsletters)) {
         $this->setNewsletterIds(array_keys(simplenews_newsletter_get_visible()));
     }
     return $this->newsletters;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     // The subscriptions field has properties which are set to NULL by ordinary
     // saving, which is wrong. The Subscriber::(un)subscribe() methods save the
     // values correctly. For each newsletter ID we check if it exists in
     // current subscriptions and new subscriptions respectively.
     $current_subscriptions = $this->entity->getSubscribedNewsletterIds();
     $subscription_values = $form_state->getValue('subscriptions');
     $new_subscriptions = array();
     foreach ($subscription_values as $subscription_value) {
         array_push($new_subscriptions, $subscription_value['target_id']);
     }
     foreach (array_keys(simplenews_newsletter_get_visible()) as $newsletter) {
         if (in_array($newsletter, $current_subscriptions) && !in_array($newsletter, $new_subscriptions)) {
             $this->entity->unsubscribe($newsletter);
         } elseif (!in_array($newsletter, $current_subscriptions) && in_array($newsletter, $new_subscriptions)) {
             $this->entity->subscribe($newsletter);
         }
     }
     $form_state->setRedirect('view.simplenews_subscribers.page_1');
     if ($this->entity->isNew()) {
         drupal_set_message($this->t('Subscriber %label has been added.', array('%label' => $this->entity->label())));
     } else {
         drupal_set_message($this->t('Subscriber %label has been updated.', array('%label' => $this->entity->label())));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function blockForm($form, FormStateInterface $form_state)
 {
     $newsletters = simplenews_newsletter_get_visible();
     foreach ($newsletters as $newsletter) {
         $options[$newsletter->id()] = $newsletter->name;
     }
     $form['newsletters'] = array('#type' => 'checkboxes', '#title' => t('Newsletters'), '#options' => $options, '#required' => TRUE, '#default_value' => $this->configuration['newsletters']);
     $form['message'] = array('#type' => 'textfield', '#title' => t('Block message'), '#size' => 60, '#maxlength' => 255, '#default_value' => $this->configuration['message']);
     /*if (\Drupal::moduleHandler()->moduleExists('views')) {
         $form['link_previous'] = array(
           '#type' => 'checkbox',
           '#title' => t('Display link to previous issues'),
           '#return_value' => 1,
           '#default_value' => variable_get('simplenews_block_l_' . $delta, 1),
           '#description' => t('Link points to newsletter/newsletter_id, which is provided by the newsletter issue list default view.'),
         );
       }*/
     /*if (\Drupal::moduleHandler()->moduleExists('views')) {
         $form['rss_feed'] = array(
           '#type' => 'checkbox',
           '#title' => t('Display RSS-feed icon'),
           '#return_value' => 1,
           '#default_value' => variable_get('simplenews_block_r_' . $delta, 1),
           '#description' => t('Link points to newsletter/feed/newsletter_id, which is provided by the newsletter issue list default view.'),
         );
       }*/
     return $form;
 }