function taxonomy_access_preserve_terms in Taxonomy Access Control 6
Same name and namespace in other branches
- 5.2 taxonomy_access.module \taxonomy_access_preserve_terms()
- 5 taxonomy_access.module \taxonomy_access_preserve_terms()
Used to preserve terms deleted by taxonomy_node_delete() that the user shouldn't have access to delete. See http://drupal.org/node/92355 and http://drupal.org/node/93086
@todo Should be possible to replace this with #access per term-field.
1 call to taxonomy_access_preserve_terms()
- taxonomy_access_form_alter in ./
taxonomy_access.module - Implements hook_form_alter().
File
- ./
taxonomy_access.module, line 932 - Allows administrators to specify how each category (in the taxonomy) can be used by various roles.
Code
function taxonomy_access_preserve_terms($node) {
$nid = $node->nid;
// prepare/cache return value
static $tids = array();
// a valid numeric nid is required
if (!is_numeric($nid)) {
return array();
}
// use cached values if possible
if (isset($tids[$nid])) {
return $tids[$nid];
}
// get a list of terms this user has access to/over
// (invokes hook_db_rewrite_sql() to limit access)
$user_terms = taxonomy_node_get_terms($node);
// get a list of all terms this node is in regardless of user's
// access settings. Don't use db_rewrite_sql() api call here (or
// any other API call, the taxonomy API functions all use
// db_rewrite_sql() so we must query the database tables directly)
$result = db_query('SELECT tid FROM {term_node} WHERE vid = %d', $node->vid);
$tids[$nid] = array();
while ($row = db_fetch_array($result)) {
// only include those terms the current user does not have access to
if (!isset($user_terms[$row['tid']])) {
$tids[$nid][$row['tid']] = $row['tid'];
}
}
// return only terms current user does not have access
// to and therefore need restoring after edit/update
return $tids[$nid];
}