Projet

Général

Profil

Paste
Télécharger (2,99 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_user / ldap_user.api.php @ 91af538d

1
<?php
2

    
3
/**
4
 * @file
5
 * Hooks and functions relevant to developers.
6
 */
7

    
8
/**
9
 * Hook_ldap_user_attrs_alter().
10
 *
11
 * Alter list of available drupal user targets (fields, properties, etc.)
12
 *   for ldap_user provisioning mapping form (admin/config/people/ldap/user)
13
 *
14
 * return array with elements of the form:
15
 * [<field_type>.<field_name>] => array(
16
 *   'name' => string for user friendly name for the UI,
17
 *   'source' => ldap attribute (even if target of synch.  this should be refactored at some point to avoid confusion)
18
 *   'configurable' =>
19
 *   'configurable_to_drupal'  0 | 1, is this configurable?
20
 *   'configurable_to_ldap' =>  0 | 1, is this configurable?
21
 *   'user_tokens' => <user_tokens>
22
 *   'convert' => 1 | 0 convert from binary to string for storage and comparison purposes
23
 *   'direction' => LDAP_USER_PROV_DIRECTION_TO_DRUPAL_USER or LDAP_USER_PROV_DIRECTION_TO_LDAP_ENTRY leave empty if configurable
24
 *   'config_module' => module providing synching configuration.
25
 *   'prov_module' => module providing actual synching of attributes.
26
 *   'prov_events' => array( of LDAP_USER_EVENT_* constants indicating during which synch actions field should be synched)
27
 *         - four permutations available
28
 *            to ldap:   LDAP_USER_EVENT_CREATE_LDAP_ENTRY,  LDAP_USER_EVENT_SYNCH_TO_LDAP_ENTRY,
29
 *            to drupal: LDAP_USER_EVENT_CREATE_DRUPAL_USER, LDAP_USER_EVENT_SYNCH_TO_DRUPAL_USER
30
 *   )
31
 *
32
 * where
33
 * 'field_type' is one of the following:
34
 *   'property' (user property such as mail, picture, timezone that is not a field)
35
 *   'field' (any field attached to the user such as field_user_lname)
36
 *   'profile2' (profile2 fields)
37
 *   'data' ($user->data array.  field_name will be used as key such as $user->data[<field_name>] = mapped value
38
 * 'field_name' machine name of property, field, profile2 field, or data associative array key
39
 */
40
function hook_ldap_user_attrs_list_alter(&$available_user_attrs, &$params) {
41

    
42
  /** search for _ldap_user_attrs_list_alter for good examples
43
  * the general trick to implementing this hook is:
44
  *   make sure to specify config and synch module
45
  *   if its configurable by ldap_user module, don't specify convert, user_tokens, direction.  these will be set by UI and stored values
46
  *   be sure to merge with existing values as ldap_user configured values will already exist in $available_user_attrs
47
  */
48

    
49
}
50

    
51
/**
52
 * Allow modules to alter the user object in the context of an ldap entry
53
 * during synchronization.
54
 *
55
 * @param array $edit
56
 *   The edit array (see hook_user_insert). Make changes to this object as
57
 *   required.
58
 * @param array $ldap_user,
59
 *   for structure @see LdapServer::userUserNameToExistingLdapEntry()
60
 *   Array, the ldap user object relating to the drupal user.
61
 * @param object $ldap_server
62
 *   The LdapServer object from which the ldap entry was fetched.
63
 * @param int $prov_event
64
 */
65
function hook_ldap_user_edit_user_alter(&$edit, &$ldap_user, $ldap_server, $prov_event) {
66
  $edit['myfield'] = $ldap_server->getAttributeValue($ldap_user, 'myfield');
67
}