Index: adminrole.info =================================================================== --- adminrole.info (revision 6733) +++ adminrole.info (working copy) @@ -1,3 +1,3 @@ name = Admin Role -description = Create a role to be "admin" and automatically assign all perms to that role. +description = "Automatically assign all permissions to an admin role." package = User Access \ No newline at end of file Index: adminrole.module =================================================================== --- adminrole.module (revision 6733) +++ adminrole.module (working copy) @@ -26,7 +26,8 @@ if ($may_cache) { $items[] = array( 'path' => 'admin/settings/adminrole', - 'title' => t('adminrole'), + 'title' => t('Admin Role'), + 'description' => t('Change which role is a "admin" Role with full perms'), 'callback' => 'drupal_get_form', 'callback arguments' => array('adminrole_admin_settings'), 'access' => user_access('administer site configuration'), @@ -40,44 +41,54 @@ 'type' => MENU_SUGGESTED_ITEM ); } + return $items; } +/** + * Sets permissions + */ function adminrole_update_perms() { if ($admin_role = variable_get('adminrole_adminrole', 0)) { $perms = array(); + foreach (module_list(FALSE, FALSE, TRUE) as $module) { if ($permissions = module_invoke($module, 'perm')) { $perms = array_merge($perms, $permissions); } } + db_query('DELETE FROM {permission} WHERE rid = %d', $admin_role); if (count($perms)) { db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $admin_role, implode(', ', $perms)); } + drupal_set_message(t('Admin Permissions Set')); } } +/** + * Settings form + */ function adminrole_admin_settings() { $form = array(); + $form['adminrole_adminrole'] = array( '#type' => 'select', '#title' => t('Admin Roles'), '#default_value' => variable_get('adminrole_adminrole', 0), - '#description' => t("Which Role is Admin?"), + '#description' => t('Which Role is Admin?'), '#options' => array_merge(array(0 => t('-- Please Select One --')), user_roles()), ); + return system_settings_form($form); } +/** + * Sets a callback on forms to invoke adminrole_update_perms() + */ function adminrole_form_alter($form_id, &$form) { - if ($form_id == 'system_modules') { - $form['#submit']["adminrole_update_perms"] = array(); + if (in_array($form_id, array('system_modules', 'adminrole_update_perms'))) { + $form['#submit']['adminrole_update_perms'] = array(); } -} - - - - - +}