You are here

function simple_ldap_user_translate_basic_ldap_to_drupal in Simple LDAP 7.2

Converts "basic" data types. That is, anything that can be loaded and saved with a simple string keyed to 'value' without format translation. This would include most textfields and number fields, but not timestamps, which need to be translated to/from LDAP's time format, or Taxonomy Terms that need to be mapped to a TID in Drupal.

Parameters

array &$edit : The $edit array to modify if the field needs to be saved. Will be passed to user_save().

array $info : Drupal field description as returned by field_info_field().

array $items: The current value of the Drupal field.

array $ldap_attr: The values in the LDAP attribute. Includes $ldap_attr['count'].

string $language:

1 string reference to 'simple_ldap_user_translate_basic_ldap_to_drupal'
simple_ldap_user_simple_ldap_data_handlers in simple_ldap_user/simple_ldap_user.module
Implements HOOK_simple_ldap_data_handlers()

File

simple_ldap_user/simple_ldap_user.ldap_handlers.inc, line 30

Code

function simple_ldap_user_translate_basic_ldap_to_drupal(&$edit, $info, $items, $ldap_attr, $language) {

  // Synchronize types that go in ['value'] and are strings
  $dirty = FALSE;
  for ($i = 0; $i < $ldap_attr['count']; $i++) {
    if ($i < $info['cardinality'] || $info['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
      $edit[$info['field_name']][$language][$i]['value'] = $ldap_attr[$i];
      if ($items[$i]['value'] != $ldap_attr[$i]) {
        $dirty = TRUE;
      }
    }
  }

  // Check if any changes were actually made.
  if (!$dirty) {
    unset($edit[$info['field_name']]);
  }
}