You are here

public function Subscriber::getUser in Simplenews 8

Same name and namespace in other branches
  1. 8.2 src/Entity/Subscriber.php \Drupal\simplenews\Entity\Subscriber::getUser()
  2. 3.x 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

2 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.

File

src/Entity/Subscriber.php, line 113

Class

Subscriber
Defines the simplenews subscriber entity.

Namespace

Drupal\simplenews\Entity

Code

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