You are here

function ldap_user_token_tokenize_entry in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 7.2 ldap_user/ldap_user.module \ldap_user_token_tokenize_entry()

Turn an ldap entry into a token array suitable for the t() function

Parameters

drupal user object $account:

array $token_keys as list of token/value pairs to generate:

string prefix token prefix such as !,%,[:

string suffix token suffix such as ]:

Return value

token array suitable for t() functions of with lowercase keys as exemplified below

1 call to ldap_user_token_tokenize_entry()
ldap_user_token_replace in ldap_user/ldap_user.module

File

ldap_user/ldap_user.module, line 1131
Module for the LDAP User Entity

Code

function ldap_user_token_tokenize_entry($account, $token_keys, $pre = LDAP_SERVERS_TOKEN_PRE, $post = LDAP_SERVERS_TOKEN_POST, $user_entity = NULL) {
  $detailed_watchdog_log = variable_get('ldap_help_watchdog_detail', 0);
  $tokens = array();
  if (!$user_entity) {
    list($discard, $user_entity) = ldap_user_load_user_acct_and_entity($account->uid, 'uid');
  }
  foreach ($token_keys as $token_key) {

    // target id is of form field.lname, property.mail, field.dept:0, etc.
    list($type, $attr_ordinal) = explode('.', $token_key);
    $parts = explode(':', $attr_ordinal);
    $attr = $parts[0];
    $ordinal = count($parts) > 1 ? $parts[1] : 0;
    $token = $pre . $token_key . $post;
    switch ($type) {
      case 'field':
        if (isset($user_entity->{$attr}['und'][$ordinal]['value'])) {
          $tokens[$token] = $user_entity->{$attr}['und'][$ordinal]['value'];
        }
        break;
      case 'property':
        if (property_exists($account, $attr)) {
          $tokens[$token] = $account->{$attr};
        }
        break;
    }
  }
  return $tokens;
}