You are here

public function Server::deriveEmailFromLdapResponse in Lightweight Directory Access Protocol (LDAP) 8.4

Returns the user's email from the LDAP entry.

Parameters

\Symfony\Component\Ldap\Entry $ldap_entry: The LDAP entry.

Return value

string The user's mail value.

Overrides ServerInterface::deriveEmailFromLdapResponse

File

ldap_servers/src/Entity/Server.php, line 424

Class

Server
Defines the Server entity.

Namespace

Drupal\ldap_servers\Entity

Code

public function deriveEmailFromLdapResponse(Entry $ldap_entry) : string {
  $mail = '';

  // Not using template.
  if ($this
    ->getMailAttribute() && $ldap_entry
    ->hasAttribute($this
    ->getMailAttribute(), FALSE)) {
    $mail = $ldap_entry
      ->getAttribute($this
      ->getMailAttribute(), FALSE)[0];
  }
  elseif ($this
    ->getMailTemplate()) {

    // Template is of form [cn]@illinois.edu.
    $mail = $this->tokenProcessor
      ->ldapEntryReplacementsForDrupalAccount($ldap_entry, $this
      ->getMailTemplate());
  }
  return $mail;
}