You are here

function roleassign_form_alter in RoleAssign 7

Same name and namespace in other branches
  1. 8 roleassign.module \roleassign_form_alter()
  2. 5 roleassign.module \roleassign_form_alter()
  3. 6 roleassign.module \roleassign_form_alter()
  4. 7.2 roleassign.module \roleassign_form_alter()

Implements hook_form_alter().

Adds checkboxes for assignable roles to the user edit form.

_state

Parameters

array $form:

string $form_id:

File

./roleassign.module, line 64
Allows site administrators to further delegate the task of managing user's roles.

Code

function roleassign_form_alter(array &$form, array &$form_state, $form_id) {

  // Do nothing if the user already has 'administer permissions' permission.
  if (user_access('administer permissions')) {
    return;
  }

  // Do nothing if the user doesn't have both 'administer users' and
  // 'assign roles' permissions.
  if (!user_access('administer users') || !user_access('assign roles')) {
    return;
  }

  // Do nothing if right form isn't shown.
  if ($form_id == 'user_register_form' || $form_id == 'user_profile_form' && isset($form['account'])) {

    // Add the checkboxes to the user edit page.
    _roleassign_module_load_include('admin.inc');
    _roleassign_form_alter($form, $form_state, $form_id);
  }
  elseif ($form_id == 'system_modules' && !user_access('administer roles')) {

    // Keep the (restricted) user from disabling this module.
    $form['modules']['roleassign']['enable']['#disabled'] = TRUE;
    $form['modules']['roleassign']['description']['#markup'] .= '<br /><span class="warning" title="' . t('You are not allowed to disable this module.') . '">' . t('(protected)') . '</span>';
  }
}