You are here

function role_delegation_roles_form_submit in Role Delegation 5

Same name and namespace in other branches
  1. 6 role_delegation.module \role_delegation_roles_form_submit()
  2. 7 role_delegation.module \role_delegation_roles_form_submit()

Saves the roles assigned to the account given in the form.

File

./role_delegation.module, line 125
This module allows site administrators to grant some roles the authority to assign selected roles to users, without them needing the 'administer access control' permission.

Code

function role_delegation_roles_form_submit($form_id, $form_values) {
  if (is_array($form_values['roles']) && isset($form_values['account']->uid)) {
    $account = user_load(array(
      'uid' => (int) $form_values['account']->uid,
    ));
    $myroles = array();
    $rolenames = user_roles(TRUE);
    foreach (array_keys(array_filter($form_values['roles'])) as $rid) {
      $myroles[$rid] = $rolenames[$rid];

      // we don't need to have the role name
    }
    user_save($account, array(
      'roles' => $myroles,
    ));

    // Delete the user's menu cache.
    cache_clear_all($form_values['account']->uid . ':', 'cache_menu', TRUE);
    drupal_set_message(t('The roles have been updated.'));
  }
}