You are here

public static function Subscriber::loadByUid in Simplenews 8.2

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

Load a simplenews newsletter subscriber object by uid.

Parameters

int $uid: Subscriber user id.

bool $create: (optional) Whether to create a new subscriber if none exists. Defaults to TRUE.

Return value

\Drupal\simplenews\SubscriberInterface Newsletter subscriber entity, FALSE if subscriber does not exist.

Overrides SubscriberInterface::loadByUid

8 calls to Subscriber::loadByUid()
SimplenewsSubscriptionBlock::build in src/Plugin/Block/SimplenewsSubscriptionBlock.php
Builds and returns the renderable array for this block plugin.
simplenews_node_view in ./simplenews.module
Implements hook_node_view().
simplenews_user_delete in ./simplenews.module
Implements hook_user_delete().
simplenews_user_login in ./simplenews.module
Implements hook_user_login().
simplenews_user_presave in ./simplenews.module
Implements hook_user_presave().

... See full list

File

src/Entity/Subscriber.php, line 421

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

public static function loadByUid($uid, $create = FALSE) {
  $subscriber = FALSE;
  if ($uid) {
    $subscribers = \Drupal::entityTypeManager()
      ->getStorage('simplenews_subscriber')
      ->loadByProperties([
      'uid' => $uid,
    ]);
    $subscriber = reset($subscribers);
  }
  if ($create && !$subscriber) {
    $subscriber = static::create([
      'uid' => $uid,
    ]);
  }
  return $subscriber;
}