You are here

function taxonomy_access_set_default_grants in Taxonomy Access Control 6

Same name and namespace in other branches
  1. 7 taxonomy_access.module \taxonomy_access_set_default_grants()

Updates default permissions for a role for a vocabulary. Note: This function adds nodes to the affected nodes cache. Callers should run _taxonomy_access_node_access_update() on _taxonomy_access_cache_affected_nodes() after all changes are processed.

Parameters

$vid: The vocab to add the permission for.

$rid: The role id to add the permission to.

$grants: A hash of the grants in the form of $grants['perm'] = boolean A value of 1 will grant the permission for this user and term.

$skip_nodes: A flag indicating whether to skip node updates when processing.

1 call to taxonomy_access_set_default_grants()
taxonomy_access_admin_form_submit in ./taxonomy_access.admin.inc
Submit handler for the administration form at admin/user/taxonomy_access.

File

./taxonomy_access.module, line 865
Allows administrators to specify how each category (in the taxonomy) can be used by various roles.

Code

function taxonomy_access_set_default_grants($vid, $rid = NULL, $grants = NULL, $skip_nodes = FALSE) {
  if (!is_numeric($vid) || isset($rid) && !is_numeric($rid)) {
    return FALSE;
  }

  // Assemble $row object for Schema API.
  $row = new stdClass();
  $row->vid = $vid;
  $row->rid = $rid;
  if (isset($grants) && is_array($grants)) {
    foreach ($grants as $op => $value) {
      if (is_numeric($value)) {
        $grant_name = "grant_{$op}";
        $row->{$grant_name} = $value;
      }
    }
  }
  if (!$skip_nodes) {

    // If we are updating the global default, flag node access for rebuild.
    if ($vid === 0) {
      drupal_set_message(t("You have modified a global default, so you should see a message indicating that content access permissions need to be rebuilt.  However, you can wait to do this until you have finished any other changes you wish to make to the Taxonomy Access Permissions."), 'warning');
      node_access_needs_rebuild(TRUE);
    }
    else {
      $affected_nodes = _taxonomy_access_get_nodes_for_vocabulary($vid, $rid);
    }
  }

  // Delete old entries.
  db_query("DELETE FROM {term_access_defaults} WHERE vid = %d AND rid = %d", $vid, $rid);

  // Insert new entries.
  drupal_write_record('term_access_defaults', $row);

  // Add any affected nodes to the cache to be updated by the submit handler.
  if (!empty($affected_nodes)) {
    _taxonomy_access_cache_affected_nodes($affected_nodes);
  }
}