You are here

function ldap_servers_ldap_user_attrs_list_alter in Lightweight Directory Access Protocol (LDAP) 8.2

Same name and namespace in other branches
  1. 8.3 ldap_servers/ldap_servers.module \ldap_servers_ldap_user_attrs_list_alter()
  2. 7.2 ldap_servers/ldap_servers.module \ldap_servers_ldap_user_attrs_list_alter()

Implements hook_ldap_user_attrs_list_alter().

File

ldap_servers/ldap_servers.module, line 343

Code

function ldap_servers_ldap_user_attrs_list_alter(&$available_user_attrs, &$params) {

  //debug('ldap_servers_ldap_user_attrs_list_alter'); debug($available_user_attrs); debug($params);
  if (isset($params['ldap_server']) && $params['ldap_server']) {
    $ldap_server = $params['ldap_server'];
  }
  else {
    return;

    // without a server id, ldap_servers module has nothing to offer
  }
  $ldap_user_conf = $params['ldap_user_conf'];
  $direction = $params['direction'];
  $tokens = array(
    '!edit_link' => l($ldap_server->editPath, $ldap_server->editPath),
    '!sid' => $ldap_server->sid,
  );
  $server_edit_path = 'admin/config/people/ldap/servers/edit/' . $ldap_server->sid;
  if ($direction == LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER) {

    /** these 4 user fields indentify where in ldap and which ldap server they are associated with.
         they are required for a Drupal account to be "ldap associated" regardless of if any other
         fields/properties are provisioned or synched
        */
    if ($ldap_server->unique_persistent_attr) {
      foreach (array(
        'field.ldap_user_puid_sid',
        'field.ldap_user_puid',
        'field.ldap_user_puid_property',
      ) 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();
        }
      }
      $available_user_attrs['[field.ldap_user_puid_sid]'] = array(
        'name' => t('Field: sid providing PUID'),
        'configurable_to_drupal' => 0,
        'configurable_to_ldap' => 1,
        'source' => t('!sid', $tokens),
        'notes' => 'not configurable',
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
        'enabled' => TRUE,
        'prov_events' => array(
          LDAP_USER_EVENT_CREATE_DRUPAL_USER,
        ),
        'config_module' => 'ldap_servers',
        'prov_module' => 'ldap_user',
      ) + $available_user_attrs['[field.ldap_user_puid_sid]'];
      $available_user_attrs['[field.ldap_user_puid]'] = array(
        'name' => t('Field: PUID', $tokens),
        'configurable_to_drupal' => 0,
        'configurable_to_ldap' => 1,
        'source' => '[' . $ldap_server->unique_persistent_attr . ']',
        'notes' => 'configure at ' . $server_edit_path,
        'convert' => $ldap_server->unique_persistent_attr_binary,
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
        'enabled' => TRUE,
        'prov_events' => array(
          LDAP_USER_EVENT_CREATE_DRUPAL_USER,
        ),
        'config_module' => 'ldap_servers',
        'prov_module' => 'ldap_user',
      ) + $available_user_attrs['[field.ldap_user_puid]'];
      $available_user_attrs['[field.ldap_user_puid_property]'] = array(
        'name' => t('Field: PUID Attribute', $tokens),
        'configurable_to_drupal' => 0,
        'configurable_to_ldap' => 1,
        'source' => $ldap_server->unique_persistent_attr,
        'notes' => 'configure at ' . $server_edit_path,
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
        'enabled' => TRUE,
        'prov_events' => array(
          LDAP_USER_EVENT_CREATE_DRUPAL_USER,
        ),
        'config_module' => 'ldap_servers',
        'prov_module' => 'ldap_user',
      ) + $available_user_attrs['[field.ldap_user_puid_property]'];
    }
    $token = '[field.ldap_user_current_dn]';
    if (!isset($available_user_attrs[$token]) || !is_array($available_user_attrs[$token])) {
      $available_user_attrs[$token] = array();
    }
    $available_user_attrs[$token] = array(
      'name' => t('Field: Most Recent DN', $tokens),
      'configurable_to_drupal' => 0,
      'configurable_to_ldap' => 0,
      'source' => '[dn]',
      'notes' => 'not configurable',
      'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
      'enabled' => TRUE,
      'prov_events' => array(
        LDAP_USER_EVENT_CREATE_DRUPAL_USER,
        LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
      ),
      'config_module' => 'ldap_servers',
      'prov_module' => 'ldap_user',
    ) + $available_user_attrs[$token];
    if ($ldap_user_conf->provisionsDrupalAccountsFromLdap) {
      if (!isset($available_user_attrs['[property.name]']) || !is_array($available_user_attrs['[property.name]'])) {
        $available_user_attrs['[property.name]'] = array();
      }
      $available_user_attrs['[property.name]'] = array(
        'name' => 'Property: Username',
        'source' => '[' . $ldap_server->user_attr . ']',
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
        'enabled' => TRUE,
        'prov_events' => array(
          LDAP_USER_EVENT_CREATE_DRUPAL_USER,
          LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
        ),
        'config_module' => 'ldap_servers',
        'prov_module' => 'ldap_user',
      ) + $available_user_attrs['[property.name]'];
      if (!isset($available_user_attrs['[property.mail]']) || !is_array($available_user_attrs['[property.mail]'])) {
        $available_user_attrs['[property.mail]'] = array();
      }
      $available_user_attrs['[property.mail]'] = array(
        'name' => 'Property: Email',
        'source' => $ldap_server->mail_template ? $ldap_server->mail_template : '[' . $ldap_server->mail_attr . ']',
        'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
        'enabled' => TRUE,
        'prov_events' => array(
          LDAP_USER_EVENT_CREATE_DRUPAL_USER,
          LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
        ),
        'config_module' => 'ldap_servers',
        'prov_module' => 'ldap_user',
      ) + $available_user_attrs['[property.mail]'];
      if ($ldap_server->picture_attr) {
        if (!isset($available_user_attrs['[property.picture]']) || !is_array($available_user_attrs['[property.picture]'])) {
          $available_user_attrs['[property.picture]'] = array();
        }
        $available_user_attrs['[property.picture]'] = array(
          'name' => 'Property: Picture',
          'source' => '[' . $ldap_server->picture_attr . ']',
          'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER,
          'enabled' => TRUE,
          'prov_events' => array(
            LDAP_USER_EVENT_CREATE_DRUPAL_USER,
            LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER,
          ),
          'config_module' => 'ldap_servers',
          'prov_module' => 'ldap_user',
        ) + $available_user_attrs['[property.picture]'];
      }
    }
  }

  // debug('available_user_attrs2'); debug($available_user_attrs);
}