function ldap_user_ldap_user_attrs_list_alter in Lightweight Directory Access Protocol (LDAP) 8.2
Same name and namespace in other branches
- 8.3 ldap_user/ldap_user.module \ldap_user_ldap_user_attrs_list_alter()
- 7.2 ldap_user/ldap_user.module \ldap_user_ldap_user_attrs_list_alter()
Implements hook_ldap_user_attrs_list_alter().
File
- ldap_user/
ldap_user.module, line 245 - Module for the LDAP User Entity
Code
function ldap_user_ldap_user_attrs_list_alter(&$available_user_attrs, &$params) {
$sid = isset($params['ldap_server']) && is_object($params['ldap_server']) ? $params['ldap_server']->sid : LDAP_USER_NO_SERVER_SID;
$ldap_user_conf = $params['ldap_user_conf'];
$direction = isset($params['direction']) ? $params['direction'] : LDAP_USER_PROV_DIRECTION_NONE;
if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
$available_user_attrs['[property.name]'] = array(
'name' => 'Property: Username',
'source' => '',
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
'enabled' => TRUE,
'prov_events' => array(
LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
),
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'configurable_to_ldap' => TRUE,
);
$available_user_attrs['[property.mail]'] = array(
'name' => 'Property: Email',
'source' => '',
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
'enabled' => TRUE,
'prov_events' => array(
LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
),
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'configurable_to_ldap' => TRUE,
);
$available_user_attrs['[property.picture]'] = array(
'name' => 'Property: picture',
'source' => '',
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
'enabled' => TRUE,
'prov_events' => array(
LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
),
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'configurable_to_ldap' => TRUE,
);
$available_user_attrs['[property.uid]'] = array(
'name' => 'Property: Drupal User Id (uid)',
'source' => '',
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
'enabled' => TRUE,
'prov_events' => array(
LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
),
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'configurable_to_ldap' => TRUE,
);
}
// 1. Drupal user properties
// 1.a make sure empty array are present so array + function works
foreach (array(
'property.status',
'property.timezone',
'property.signature',
) as $i => $property_id) {
$property_token = '[' . $property_id . ']';
if (!isset($available_user_attrs[$property_token]) || !is_array($available_user_attrs[$property_token])) {
$available_user_attrs[$property_token] = array();
}
}
//@todo make these merges so they don't override saved values such as 'enabled'
$available_user_attrs['[property.status]'] = $available_user_attrs['[property.status]'] + array(
'name' => 'Property: Acount Status',
'configurable_to_drupal' => 1,
'configurable_to_ldap' => 1,
'user_tokens' => '1=enabled, 0=blocked.',
'enabled' => FALSE,
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
);
$available_user_attrs['[property.timezone]'] = $available_user_attrs['[property.timezone]'] + array(
'name' => 'Property: User Timezone',
'configurable_to_drupal' => 1,
'configurable_to_ldap' => 1,
'enabled' => FALSE,
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
);
$available_user_attrs['[property.signature]'] = $available_user_attrs['[property.signature]'] + array(
'name' => 'Property: User Signature',
'configurable_to_drupal' => 1,
'configurable_to_ldap' => 1,
'enabled' => FALSE,
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
);
// 2. Drupal user fields
$user_fields = field_info_instances('user', 'user');
foreach ($user_fields as $field_name => $field_instance) {
$field_id = "[field.{$field_name}]";
if (!isset($available_user_attrs[$field_id]) || !is_array($available_user_attrs[$field_id])) {
$available_user_attrs[$field_id] = array();
}
$available_user_attrs[$field_id] = $available_user_attrs[$field_id] + array(
'name' => t('Field') . ': ' . $field_instance['label'],
'configurable_to_drupal' => 1,
'configurable_to_ldap' => 1,
'enabled' => FALSE,
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
);
}
if (!$ldap_user_conf->provisionsDrupalAccountsFromLdap) {
$available_user_attrs['[property.mail]']['config_module'] = 'ldap_user';
$available_user_attrs['[property.name]']['config_module'] = 'ldap_user';
$available_user_attrs['[property.picture]']['config_module'] = 'ldap_user';
}
if ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY) {
$available_user_attrs['[password.random]'] = array(
'name' => 'Pwd: Random',
'source' => '',
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
'enabled' => TRUE,
'prov_events' => array(
LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
),
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'configurable_to_ldap' => TRUE,
);
// use user password when available fall back to random pwd
$available_user_attrs['[password.user-random]'] = array(
'name' => 'Pwd: User or Random',
'source' => '',
'direction' => LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY,
'enabled' => TRUE,
'prov_events' => array(
LDAP_USER_EVENT_CREATE_LDAP_ENTRY,
LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
),
'config_module' => 'ldap_user',
'prov_module' => 'ldap_user',
'configurable_to_ldap' => TRUE,
);
}
//this is where need to be added to arrays
if (!empty($ldap_user_conf->ldapUserSynchMappings[$direction])) {
foreach ($ldap_user_conf->ldapUserSynchMappings[$direction] as $target_token => $mapping) {
if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER && isset($mapping['user_attr'])) {
$key = $mapping['user_attr'];
}
elseif ($direction == LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY && isset($mapping['ldap_attr'])) {
$key = $mapping['ldap_attr'];
}
else {
continue;
}
foreach (array(
'ldap_attr',
'user_attr',
'convert',
'direction',
'enabled',
'prov_events',
) as $k) {
if (isset($mapping[$k])) {
$available_user_attrs[$key][$k] = $mapping[$k];
}
else {
$available_user_attrs[$key][$k] = NULL;
}
$available_user_attrs[$key]['config_module'] = 'ldap_user';
$available_user_attrs[$key]['prov_module'] = 'ldap_user';
}
if ($mapping['user_attr'] == 'user_tokens') {
$available_user_attrs['user_attr'] = $mapping['user_tokens'];
}
}
}
// 3. profile2 fields
// 4. $user->data array. will need to be added manually. perhaps better not to implement this at all?
}