You are here

function ldap_feeds_drupal_user_legend in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_feeds/ldap_feeds.module \ldap_feeds_drupal_user_legend()
  2. 7 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 140

Code

function ldap_feeds_drupal_user_legend(&$form, $importer) {
  $sources = [];
  $servers = ldap_servers_get_servers(NULL, 'enabled');
  $form['legendset']['#description'] = "";
  $drupal_user_attributes = $importer->config['fetcher']['config']['availableDrupalUserAttributes'];
  foreach ($drupal_user_attributes as $attr_name => $attr_conf) {
    $id = $attr_conf['token'];
    $sources[$id] = [
      'name' => [
        '#markup' => $id,
      ],
      'description' => [
        '#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) {
        if ($attr_name == 'count') {
          continue;
        }
        $id = $attr_conf['token'];
        if ($account) {
          $sources[$id] = [
            'name' => [
              '#markup' => $id,
            ],
            'description' => [
              '#markup' => $account->{$attr_name},
            ],
          ];
        }
      }
      $ldap_user = ldap_servers_get_user_ldap_data($ldap_server->testingDrupalUsername, $sid);
      foreach ($ldap_user['attr'] as $id => $value) {
        if (!is_numeric($id) && is_scalar($ldap_user['attr'][$id][0]) && $ldap_user['attr'][$id]['count'] == 1) {
          $sources[$id] = [
            'name' => [
              '#markup' => $id,
            ],
            'description' => [
              '#markup' => $ldap_user['attr'][$id][0],
            ],
          ];
        }
        elseif ($ldap_user['attr'][$id]['count'] > 1) {
          $item = t('MULTIVALUED ATTRIBUTE:') . join(" , \n", $ldap_user['attr'][$id]);
          $sources[$id] = [
            'name' => [
              '#markup' => $id,
            ],
            'description' => [
              '#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.', [
        '%sid' => $sid,
        '%testing_user' => $ldap_server->testingDrupalUsername,
      ]);
    }
    else {
      foreach ([
        'dn' => 'distinguished name',
        'cn' => 'cname',
      ] as $id => $value) {
        $sources[$id] = [
          'name' => [
            '#markup' => $id,
          ],
          'description' => [
            '#markup' => $value,
          ],
        ];
      }
    }
  }
  $form['legendset']['legend']['sources'] = $sources;
}