You are here

function simplenews_user_insert in Simplenews 8.2

Same name and namespace in other branches
  1. 8 simplenews.module \simplenews_user_insert()
  2. 7.2 simplenews.module \simplenews_user_insert()
  3. 7 simplenews.module \simplenews_user_insert()
  4. 3.x simplenews.module \simplenews_user_insert()

Implements hook_user_insert().

If there is a matching subscription, link it to this account.

File

./simplenews.module, line 435
Simplenews node handling, sent email, newsletter block and general hooks.

Code

function simplenews_user_insert(UserInterface $account) {
  if ($subscriber = Subscriber::loadByMail($account
    ->getEmail())) {
    $subscriber
      ->fillFromAccount($account);

    // Set inactive if not created by an administrator.
    if (!\Drupal::currentUser()
      ->hasPermission('administer users')) {

      // This user will be activated on first login (see simplenews_user_login)
      $subscriber
        ->setStatus(FALSE);
    }
    else {
      $subscriber
        ->setStatus(TRUE);
    }
    $subscriber
      ->save();
  }
}