You are here

function hook_ldap_user_edit_user_alter in Lightweight Directory Access Protocol (LDAP) 8.3

Same name and namespace in other branches
  1. 8.4 ldap_user/ldap_user.api.php \hook_ldap_user_edit_user_alter()
  2. 8.2 ldap_user/ldap_user.api.php \hook_ldap_user_edit_user_alter()
  3. 7.2 ldap_user/ldap_user.api.php \hook_ldap_user_edit_user_alter()

Alter the user object in the context of an LDAP entry during synchronization.

Parameters

User $account: The edit array (see hook_user_insert). Make changes to this object as required.

array $ldap_user: The LDAP user object relating to the Drupal user. For structure @see LdapServer::matchUsernameToExistingLdapEntry()

array $context: Contains ldap_server and provisioning events.

1 invocation of hook_ldap_user_edit_user_alter()
DrupalUserProcessor::applyAttributesToAccount in ldap_user/src/Processor/DrupalUserProcessor.php
Apply field values to user account.

File

ldap_user/ldap_user.api.php, line 57
Hooks and functions relevant to developers.

Code

function hook_ldap_user_edit_user_alter(User &$account, array &$ldap_user, array $context) {
  $tokenProcessor = \Drupal::service('ldap.token_processor');
  $value = $tokenProcessor
    ->tokenReplace($ldap_user['attr'], '[sn]', 'ldap_entry');
  $account
    ->set('myfield', $value);
}