You are here

public function Subscriber::getSubscription in Simplenews 3.x

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

Returns the subscription to a given newsletter..

Parameters

string $newsletter_id: The ID of a newsletter.

Return value

\Drupal\simplenews\Plugin\Field\FieldType\SubscriptionItem The subscription item if the subscriber is subscribed, otherwise FALSE.

Overrides SubscriberInterface::getSubscription

2 calls to Subscriber::getSubscription()
Subscriber::subscribe in src/Entity/Subscriber.php
Add a subscription to a certain newsletter to the subscriber.
Subscriber::unsubscribe in src/Entity/Subscriber.php
Delete a subscription to a certain newsletter of the subscriber.

File

src/Entity/Subscriber.php, line 219

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

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