You are here

public function Subscriber::isSubscribed in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::isSubscribed()
  2. 3.x src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::isSubscribed()

Check if the subscriber has an active subscription to a certain newsletter.

Parameters

string $newsletter_id: The ID of a newsletter.

Return value

bool Returns TRUE if the subscriber has the subscription, otherwise FALSE.

Overrides SubscriberInterface::isSubscribed

File

src/Entity/Subscriber.php, line 189

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

public function isSubscribed($newsletter_id) {
  foreach ($this->subscriptions as $item) {
    if ($item->target_id == $newsletter_id) {
      return $item->status == SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED;
    }
  }
  return FALSE;
}