You are here

function ldap_feeds_drupal_user_legend in Lightweight Directory Access Protocol (LDAP) 7

Same name and namespace in other branches
  1. 8.2 ldap_feeds/ldap_feeds.module \ldap_feeds_drupal_user_legend()
  2. 7.2 ldap_feeds/ldap_feeds.module \ldap_feeds_drupal_user_legend()

add additional data to mapping form for drupal user fetcher

1 call to ldap_feeds_drupal_user_legend()
ldap_feeds_form_feeds_ui_mapping_form_alter in ldap_feeds/ldap_feeds.module
show some sample ldap user data to help with mapping interface

File

ldap_feeds/ldap_feeds.module, line 131

Code

function ldap_feeds_drupal_user_legend(&$form) {
  $sources = array();
  $servers = ldap_servers_get_servers(NULL, 'enabled');
  $form['legendset']['#description'] = "";
  $drupal_user_attributes = $form['#importer']->config['fetcher']['config']['availableDrupalUserAttributes'];
  foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
    $id = $attr_conf['token'];
    $sources[$id] = array(
      'name' => array(
        '#markup' => $id,
      ),
      'description' => array(
        '#markup' => '',
      ),
    );
  }
  foreach ($servers as $sid => $ldap_server) {
    if ($ldap_server->testingDrupalUsername) {
      $account = user_load_by_name($ldap_server->testingDrupalUsername);
      foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
        $id = $attr_conf['token'];
        if ($account) {
          $sources[$id] = array(
            'name' => array(
              '#markup' => $id,
            ),
            'description' => array(
              '#markup' => $account->{$attr_name},
            ),
          );
        }
      }
      $user_ldap_entry = ldap_servers_get_user_ldap_data($ldap_server->testingDrupalUsername, $sid);
      foreach ($user_ldap_entry['attr'] as $id => $value) {
        if (!is_numeric($id) && is_scalar($user_ldap_entry['attr'][$id][0]) && $user_ldap_entry['attr'][$id]['count'] == 1) {
          $sources[$id] = array(
            'name' => array(
              '#markup' => $id,
            ),
            'description' => array(
              '#markup' => $user_ldap_entry['attr'][$id][0],
            ),
          );
        }
        elseif ($user_ldap_entry['attr'][$id]['count'] > 1) {
          $item = t('MULTIVALUED ATTRIBUTE:') . join(" , \n", $user_ldap_entry['attr'][$id]);
          $sources[$id] = array(
            'name' => array(
              '#markup' => $id,
            ),
            'description' => array(
              '#markup' => $item,
            ),
          );
        }
      }
      $form['legendset']['#description'] .= t('LDAP Attributes in the source "description" column are from testing ldap user (%testing_user) on the server %sid, which is configured in
        the ldap server form.', array(
        '%sid' => $sid,
        '%testing_user' => $ldap_server->testingDrupalUsername,
      ));
    }
    else {
      foreach (array(
        'dn' => 'distinguished name',
        'cn' => 'cname',
      ) as $id => $value) {
        $sources[$id] = array(
          'name' => array(
            '#markup' => $id,
          ),
          'description' => array(
            '#markup' => $value,
          ),
        );
      }
    }
  }
  $form['legendset']['legend']['sources'] = $sources;
}