You are here

function simple_ldap_user_profile_map_form in Simple LDAP 7.2

Admin form for mapping Drupal user attributes to LDAP attributes

1 string reference to 'simple_ldap_user_profile_map_form'
simple_ldap_user_menu in simple_ldap_user/simple_ldap_user.module
Implements hook_menu().

File

simple_ldap_user/simple_ldap_user.admin.inc, line 269
Functions for Simple LDAP User admin interface.

Code

function simple_ldap_user_profile_map_form($form, $form_state) {
  $form = array();

  // Pull the fields defined for user profiles
  // ToDo: Support user profile modules
  $user_fields = simple_ldap_user_user_fields();
  $unmapped_required = array();
  $classes = simple_ldap_user_profile_classes();
  $options = simple_ldap_user_class_attrs_as_options($classes);

  // Finally, build the form
  $form['header'] = array(
    '#type' => 'markup',
    '#markup' => '<p>' . t('Select LDAP attributes to map to the Drupal user fields below.  LDAP attributes marked with an askterisk (*) are required by the LDAP schema and must be assigned to a Drupal fields.  LDAP attributes should be mapped to at most one Drupal fields.</p><p>Username, Email and Password mappings are also done on the User tab.') . '</p>',
  );
  $form['attributes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Drupal Fields to LDAP Attributes'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => 10,
  );
  foreach ($user_fields as $key => $field) {

    // Removed mapped fields from the list of MUST attributes.
    $mapped_attribute = simple_ldap_user_variable_get('simple_ldap_user_attribute_' . $key);
    unset($unmapped_required[$mapped_attribute]);

    // Add a form field.
    $form['attributes']['simple_ldap_user_attribute_' . $key] = array(
      '#type' => 'select',
      '#title' => $field['label'],
      '#description' => $field['description'],
      '#options' => $options,
      '#required' => $field['required'],
      '#default_value' => $mapped_attribute,
    );
  }

  // Give a warning about unmapped attributes.
  if (!empty($unmapped_required)) {
    drupal_set_message(t('The following attributes are required by the selected user object class(es), but are not mapped. They should be mapped here or given default values in <code>hook_simple_ldap_user_to_ldap_alter()</code>.  If they are not set, writes to LDAP may fail with an <em>object class violation</em>. !list', array(
      '!list' => theme('item_list', array(
        'items' => $unmapped_required,
      )),
    )), 'warning');
  }
  $attribute_map = simple_ldap_user_variable_get('simple_ldap_user_attribute_map');
  $delimiter_options = array(
    'array' => t('Multivalue field (array)'),
    'cr' => t('Multiline field (\\r)'),
    'dollar' => t('Dollar sign ($)'),
  );
  foreach ($attribute_map as $key => $value) {
    if (is_array($value) && count($value) > 1) {
      $form['delimiters']['simple_ldap_user_delimiter_' . $key] = array(
        '#type' => 'select',
        '#title' => $key,
        '#options' => $delimiter_options,
        '#default_value' => simple_ldap_user_variable_get('simple_ldap_user_delimiter_' . $key),
      );
    }
  }
  if (!empty($form['delimiters'])) {
    $form['delimiters'] += array(
      '#type' => 'fieldset',
      '#title' => t('Multiple Value Field Delimiters'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#weight' => 20,
    );
  }
  $form['extra_attrs_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Load Additional Attributes'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => 30,
  );
  $form['extra_attrs_fieldset']['simple_ldap_user_extra_attrs'] = array(
    '#type' => 'select',
    '#title' => t('Extra Attributes'),
    '#description' => t('Select additional unmapped attributes to load.'),
    '#options' => $options,
    '#default_value' => simple_ldap_user_variable_get('simple_ldap_user_extra_attrs'),
    '#multiple' => TRUE,
    '#attached' => array(
      'css' => array(
        drupal_get_path('module', 'simple_ldap_user') . '/simple_ldap_user_admin.css',
      ),
    ),
  );
  $form = system_settings_form($form);
  $form['#submit'][] = 'simple_ldap_user_profile_map_form_submit';
  return $form;
}