You are here

protected function SimpleLdapUserManager::userIdFromLdapUser in Simple LDAP 8

Extracts the Drupal user ID from the LdapUser.

Parameters

\Drupal\simple_ldap_user\SimpleLdapUser $user: The LDAP user object.

Return value

integer|bool The user ID.

1 call to SimpleLdapUserManager::userIdFromLdapUser()
SimpleLdapUserManager::loadDrupalUser in modules/simple_ldap_user/src/SimpleLdapUserManager.php
Load a Drupal user based on an LDAP user.

File

modules/simple_ldap_user/src/SimpleLdapUserManager.php, line 154

Class

SimpleLdapUserManager
Manages the loading and syncing of data between LDAP server and Drupal.

Namespace

Drupal\simple_ldap_user

Code

protected function userIdFromLdapUser(SimpleLdapUser $user) {
  $attribute_values = $user
    ->getAttributes();
  $name_attribute = $this->config
    ->get('name_attribute');
  $mail_attribute = $this->config
    ->get('mail_attribute');
  $cid = sprintf('uids::%s:%s', $name_attribute, $mail_attribute);
  if (array_key_exists($cid, $this->cache)) {
    return $this->cache[$cid];
  }
  $query = $this->entity_manager
    ->getStorage('user', 'OR')
    ->getQuery()
    ->condition('name', $attribute_values[$name_attribute][0])
    ->condition('mail', $attribute_values[$mail_attribute][0]);
  $results = $query
    ->execute();
  $uid = reset($results);
  $this->cache[$cid] = $uid;
  return $uid;
}