function simple_ldap_user_generate_edit_ldap_to_drupal in Simple LDAP 7.2
2 calls to simple_ldap_user_generate_edit_ldap_to_drupal()
- simple_ldap_user_sync_user_to_drupal in simple_ldap_user/
simple_ldap_user.module - Synchronizes LDAP attributes to Drupal user properties.
- simple_ldap_user_user_presave in simple_ldap_user/
simple_ldap_user.module - Implements hook_user_presave().
File
- simple_ldap_user/
simple_ldap_user.module, line 1103 - Main simple_ldap_user module file.
Code
function simple_ldap_user_generate_edit_ldap_to_drupal(&$edit, $ldap_user, $account) {
$attribute_map = simple_ldap_user_variable_get('simple_ldap_user_attribute_map');
$user_fields = simple_ldap_user_user_fields();
// Synchronize the fields in the attribute map.
foreach ($attribute_map as $ldap_attr => $drupal_fields) {
// Skip drupal-to-ldap many-to-one mappings.
$one_to_many = FALSE;
$values = array();
if (count($drupal_fields) > 2) {
if (array_key_exists('#delimiter', $drupal_fields)) {
if (array_key_exists(0, $ldap_user->{$ldap_attr})) {
$values = explode($drupal_fields['#delimiter'], $ldap_user->{$ldap_attr}[0]);
}
$values['count'] = count($values);
$one_to_many = TRUE;
}
}
else {
$values = $ldap_user->{$ldap_attr};
}
foreach ($drupal_fields as $key => $drupal_field_name) {
// Skip special items like #delimeter
if (!is_int($key)) {
continue;
}
// Skip the password field
if ($drupal_field_name == 'pass') {
continue;
}
// Skip if not in user field list
if (!array_key_exists($drupal_field_name, $user_fields)) {
continue;
}
// Map one at a time if mapping across multiple fields
// TODO: $values may not have enough entries.
if ($one_to_many) {
$map_values = array_key_exists($key, $values) ? array(
$values[$key],
'count' => 1,
) : array(
'count' => 0,
);
}
else {
$map_values = $values;
}
$field = $user_fields[$drupal_field_name];
switch ($field['module']) {
// Update the value in drupal using Field API.
case 'field':
// Get the Drupal field values and metadata.
simple_ldap_user_translate_ldap_attr_to_drupal($edit, $account, $map_values, $drupal_field_name);
break;
// Update the value directly on the user object.
case 'user':
simple_ldap_user_base_field_to_drupal($edit, $account, $map_values, $drupal_field_name);
break;
default:
watchdog('Simple LDAP', 'Field from unknown module %module. (not supported yet)', array(
'%module' => $field['module'],
), WATCHDOG_WARNING);
}
}
}
// Allow altering the Drupal user object before saving.
drupal_alter('simple_ldap_user_to_drupal', $edit, $account, $ldap_user);
}