You are here

function simple_ldap_role_user_presave in Simple LDAP 7.2

Same name and namespace in other branches
  1. 7 simple_ldap_role/simple_ldap_role.module \simple_ldap_role_user_presave()

Implements hook_user_presave().

File

simple_ldap_role/simple_ldap_role.module, line 73
Main simple_ldap_role module file.

Code

function simple_ldap_role_user_presave(&$edit, $account, $category) {

  // The Authenticated User role will be present on the edit form.
  $exclude = array(
    DRUPAL_AUTHENTICATED_RID,
  );

  // Allow altering excluded roles.
  drupal_alter('simple_ldap_role_exclude', $exclude);

  // Loop through roles submitted on form.
  if (isset($edit['name']) && isset($edit['roles'])) {
    foreach ($edit['roles'] as $rid => $value) {
      if ($value && !in_array($rid, $exclude)) {
        $role = user_role_load($rid);
        $ldap_role = SimpleLdapRole::singleton($role->name);
        $ldap_role
          ->addUser($edit['name']);
        $ldap_role
          ->save();
      }
    }
  }
}