You are here

public function Subscriber::getUser in Simplenews 3.x

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

Returns corresponding User object, if any.

Return value

\Drupal\user\UserInterface|null The corresponding User object, or NULL if the subscriber is not synced with a user.

Overrides SubscriberInterface::getUser

3 calls to Subscriber::getUser()
Subscriber::postCreate in src/Entity/Subscriber.php
Acts on a created entity before hooks are invoked.
Subscriber::postSave in src/Entity/Subscriber.php
Acts on a saved entity before the insert or update hook is invoked.
Subscriber::preSave in src/Entity/Subscriber.php
Acts on an entity before the presave hook is invoked.

File

src/Entity/Subscriber.php, line 111

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

public function getUser() {
  $uid = $this
    ->getUserId();
  if ($uid && ($user = User::load($uid))) {
    return $user;
  }
  elseif ($mail = $this
    ->getMail()) {
    return user_load_by_mail($mail) ?: NULL;
  }
  else {
    return NULL;
  }
}