You are here

function taxonomy_access_admin_delete_role in Taxonomy Access Control 6

Same name and namespace in other branches
  1. 5.2 taxonomy_access_admin.inc \taxonomy_access_admin_delete_role()

Form callback to delete all access rules for a particular role.

Parameters

$rid: The role id to disable.

2 string references to 'taxonomy_access_admin_delete_role'
taxonomy_access_admin in ./taxonomy_access.admin.inc
Menu callback (for admin/user/taxonomy_access). Renders the TAC permissions administration form.
taxonomy_access_menu in ./taxonomy_access.module
Implements hook_menu().

File

./taxonomy_access.admin.inc, line 84
Administrative interface for taxonomy access control.

Code

function taxonomy_access_admin_delete_role($form_state, $rid) {
  if (is_numeric($rid) and $rid > 2) {
    $r = db_query('SELECT grant_view, grant_update, grant_delete
       FROM {term_access_defaults}
       WHERE vid=0 AND rid=%d', $rid);
    $role_global_default = db_fetch_array($r);
    if ($role_global_default) {
      if ($_POST['confirm']) {

        // Compare this role's global default node access to auth user role.
        $auth_global_default = db_fetch_array(db_query('SELECT grant_view, grant_update, grant_delete
           FROM {term_access_defaults}
           WHERE vid=0 AND rid=2'));
        if ($role_global_default == $auth_global_default) {
          $affected_nodes = _taxonomy_access_get_nodes_for_role($rid);
        }
        else {

          // If the global default is different, this role's access changes on
          // all uncontrolled nodes, so flag node access for rebuild.
          node_access_needs_rebuild(TRUE);
        }
        db_query('DELETE FROM {term_access} WHERE rid=%d', $rid);
        db_query('DELETE FROM {term_access_defaults} WHERE rid=%d', $rid);
        if (!empty($affected_nodes)) {
          _taxonomy_access_node_access_update($affected_nodes);
        }
        drupal_set_message(t('All term access rules deleted for role %rid.', array(
          '%rid' => $rid,
        )));
        drupal_goto('admin/user/taxonomy_access');
      }
      else {
        return confirm_form($form, t('Are you sure you want to delete all grant rules for role %rid?', array(
          '%rid' => $rid,
        )), 'admin/user/taxonomy_access', t('This action cannot be undone.'), t('Delete all'), t('Cancel'));
      }
      return;
    }
  }
  return drupal_not_found();
}