function user_permissions_form_user_admin_permissions_alter in User Permissions 7
Same name and namespace in other branches
- 8 user_permissions.module \user_permissions_form_user_admin_permissions_alter()
Alters user_admin_permissions
File
- ./
user_permissions.module, line 232
Code
function user_permissions_form_user_admin_permissions_alter(&$form, &$form_state, $form_id) {
// If viewing a user permissions page, this returns early so
// it doesn't modify the form.
if (count($form['role_names']['#value']) == 1) {
$names = array_values($form['role_names']['#value']);
if (preg_match(USER_PERMISSIONS_ROLE_REGEX, array_shift($names))) {
return;
}
}
$role_id_filter = array();
// Creates an array of role IDs to use as a filter for removing
// all _user_role_N related elements from the Permissions form.
foreach (user_roles() as $rid => $name) {
if (preg_match(USER_PERMISSIONS_ROLE_REGEX, $name)) {
$role_id_filter[] = $rid;
}
}
// Removes the checkboxes from the Permissions form on the
// /admin/people/permissions page.
foreach ($form['checkboxes'] as $key => $value) {
if (in_array($key, $role_id_filter)) {
unset($form['checkboxes'][$key]);
}
}
// Removes the columns for the _user_role_N roles from the Permissions
// form on the /admin/people/permissions page.
foreach (element_children($form['role_names']) as $key) {
if (in_array($key, $role_id_filter)) {
unset($form['role_names'][$key]);
unset($form['role_names']['#value'][$key]);
}
}
}