You are here

public function LdapServer::userUsernameToLdapNameTransform in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/LdapServer.class.php \LdapServer::userUsernameToLdapNameTransform()

Parameters

$drupal_username:

$watchdog_tokens:

Return value

string

1 call to LdapServer::userUsernameToLdapNameTransform()
LdapServer::userUserNameToExistingLdapEntry in ldap_servers/LdapServer.class.php
Queries LDAP server for the user.

File

ldap_servers/LdapServer.class.php, line 1099
Defines server classes and related functions.

Class

LdapServer
LDAP Server Class.

Code

public function userUsernameToLdapNameTransform($drupal_username, &$watchdog_tokens) {
  if ($this->ldapToDrupalUserPhp && module_exists('php')) {
    global $name;
    $old_name_value = $name;
    $name = $drupal_username;
    $code = "<?php global \$name; \n" . $this->ldapToDrupalUserPhp . "; \n ?>";
    $watchdog_tokens['%code'] = $this->ldapToDrupalUserPhp;
    $code_result = php_eval($code);
    $watchdog_tokens['%code_result'] = $code_result;
    $ldap_username = $code_result;
    $watchdog_tokens['%ldap_username'] = $ldap_username;

    // Important because of global scope of $name.
    $name = $old_name_value;
    if ($this->detailedWatchdogLog) {
      watchdog('ldap_servers', '%drupal_user_name tansformed to %ldap_username by applying code <code>%code</code>', $watchdog_tokens, WATCHDOG_DEBUG);
    }
  }
  else {
    $ldap_username = $drupal_username;
  }

  // Let other modules alter the ldap name.
  $context = [
    'ldap_server' => $this,
  ];
  drupal_alter('ldap_servers_username_to_ldapname', $ldap_username, $drupal_username, $context);
  return $ldap_username;
}