You are here

adminrole.module in Admin role 5

Same filename and directory in other branches
  1. 6 adminrole.module
  2. 7 adminrole.module

This module simply gives a designated role all permissions every time the modules page is submitted.

File

adminrole.module
View source
<?php

/**
 * @file
 * This module simply gives a designated role all permissions every time the
 * modules page is submitted.
 */

/**
 * Implement hook_form_alter().
 */
function adminrole_form_alter($form_id, &$form) {
  if ($form_id == 'user_admin_settings') {

    // Administrative role option.
    $form['admin_role'] = array(
      '#type' => 'fieldset',
      '#title' => t('Administrator role'),
    );

    // Do not allow users to set the anonymous or authenticated user roles as the
    // administrator role.
    $roles = user_roles();
    unset($roles[DRUPAL_ANONYMOUS_RID]);
    unset($roles[DRUPAL_AUTHENTICATED_RID]);
    $form['admin_role']['user_admin_role'] = array(
      '#type' => 'select',
      '#title' => t('Administrator role'),
      '#default_value' => variable_get('user_admin_role', 0),
      '#options' => array(
        0 => t('Disabled'),
      ) + $roles,
      '#description' => t('This role will be automatically assigned new permissions whenever a module is enabled.'),
    );

    // Ensure the save/reset buttons have a lower weight than our fieldset.
    $form['buttons'] += array(
      '#weight' => 100,
    );
  }
  if (in_array($form_id, array(
    'system_modules',
    'user_admin_settings',
    'cck_field_perms_admin_settings_form',
  ))) {
    $form['#submit']['adminrole_update_permissions'] = array();
  }
}

/**
 * Implements hook_node_type().
 */
function adminrole_node_type($op, $node_type) {
  adminrole_update_permissions();
}

/**
 * Update the admin role with all current available permissions.
 */
function adminrole_update_permissions() {
  if ($rid = variable_get('user_admin_role', 0)) {
    $permissions = module_invoke_all('perm');
    if ($excluded = variable_get('adminrole_exclude_permissions', array())) {
      $permissions = array_diff($permissions, $excluded);
    }
    db_query('DELETE FROM {permission} WHERE rid = %d', $rid);
    if ($permissions) {
      db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', $permissions));
    }
  }
}

Functions

Namesort descending Description
adminrole_form_alter Implement hook_form_alter().
adminrole_node_type Implements hook_node_type().
adminrole_update_permissions Update the admin role with all current available permissions.