You are here

public function UserEmailVerification::isVerificationNeeded in User email verification 8

Checks: Is email verification needed for a requested user.

Parameters

int $uid: User ID, optional, if not set - current user ID will be used.

Return value

bool Result of check.

Overrides UserEmailVerificationInterface::isVerificationNeeded

File

src/UserEmailVerification.php, line 503

Class

UserEmailVerification
User email verification helper service.

Namespace

Drupal\user_email_verification

Code

public function isVerificationNeeded($uid = 0) {
  if (!$uid) {
    $uid = $this->currentUser
      ->id();
  }
  $skip_roles = $this
    ->getSkipRoles();
  $query = $this->database
    ->select(UserEmailVerificationInterface::VERIFICATION_TABLE_NAME, 'uev')
    ->fields('uev', [
    'uid',
  ])
    ->condition('uev.verified', 0, '=')
    ->condition('uev.uid', $uid, '=');
  if ($skip_roles) {
    $query
      ->leftJoin('user__roles', 'ur', 'ur.entity_id = uev.uid');
    $or = $query
      ->orConditionGroup()
      ->condition('ur.roles_target_id', $skip_roles, 'NOT IN')
      ->isNull('ur.roles_target_id');
    $query
      ->condition($or);
    $query
      ->distinct();
  }
  return (bool) $query
    ->execute()
    ->fetchField();
}