You are here

function user_permissions_form_user_profile_form_alter in User Permissions 7

Implements hook_FORM_ID_alter for the user profile form.

See also

user_profile_form()

File

./user_permissions.module, line 201

Code

function user_permissions_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#user_category'] === 'account') {

    // Removes the elements related to _user_role_N roles from the Roles form on the /user/{UID}/edit page
    foreach (user_roles() as $rid => $name) {
      if (preg_match(USER_PERMISSIONS_ROLE_REGEX, $name) && !in_array($rid, $form['account']['roles']['#default_value'])) {
        unset($form['account']['roles']['#options'][$rid]);
      }
    }
  }
}