public static function Subscriber::loadByUid in Simplenews 3.x
Same name and namespace in other branches
- 8.2 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()
- SimplenewsSubscribeTest::testDuplicate in tests/
src/ Functional/ SimplenewsSubscribeTest.php - Tests protection against duplicate subscribers.
- 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_ENTITY_TYPE_view() for node entity.
- simplenews_user_delete in ./
simplenews.module - Implements hook_ENTITY_TYPE_delete() for user entity.
- simplenews_user_login in ./
simplenews.module - Implements hook_user_login().
File
- src/
Entity/ Subscriber.php, line 436
Class
- Subscriber
- Defines the simplenews subscriber entity.
Namespace
Drupal\simplenews\EntityCode
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;
}