function taxonomy_access_taxonomy in Taxonomy Access Control 6
Same name and namespace in other branches
- 5.2 taxonomy_access.module \taxonomy_access_taxonomy()
- 5 taxonomy_access.module \taxonomy_access_taxonomy()
Implements hook_taxonomy().
File
- ./
taxonomy_access.module, line 139 - Allows administrators to specify how each category (in the taxonomy) can be used by various roles.
Code
function taxonomy_access_taxonomy($op, $type, $array = NULL) {
switch ($op) {
case 'delete':
// See taxonomy_access_form_taxonomy_form_term_alter()
// and taxonomy_access_form_taxonomy_vocabulary_confirm_delete_alter().
// Use static variables so they are available when children use the hook.
static $del_vocab;
static $del_term;
static $affected_nodes;
static $descendants;
// Check for flags & node list from our admin form submit overrides.
if (!isset($del_vocab)) {
$del_vocab = _taxonomy_access_del_vocabulary();
}
if (!isset($del_term)) {
$del_term = _taxonomy_access_del_term();
}
if (!isset($affected_nodes)) {
$affected_nodes = _taxonomy_access_cache_affected_nodes();
}
if (!isset($descendants) && $del_term) {
$descendants = _taxonomy_access_get_descendants($del_term);
}
// Clean our data for the term or vocab.
if ($type == 'term') {
db_query("DELETE FROM {term_access} WHERE tid = '%d'", $array['tid']);
}
if ($type == 'vocabulary') {
db_query("DELETE FROM {term_access_defaults} WHERE vid = '%d'", $array['vid']);
}
// Determine if and how to update node access.
// If the user deleted a vocabulary on the admin form, use cached data.
if ($del_vocab) {
// Only trigger node access update on the vocab deletion itself,
// after all the terms have been deleted.
if ($type == 'vocabulary') {
_taxonomy_access_node_access_update($affected_nodes);
}
}
elseif ($del_term) {
// Main term is first one to invoke the hook.
// To ensure that update runs only once after all descendants have
// been processed, unset each when it invokes the hook.
$key = array_search($array['tid'], $descendants);
if (!($key === FALSE)) {
// Might be zero.
unset($descendants[$key]);
}
// If there are no descendants left, process updates.
if (sizeof($descendants) == 0) {
_taxonomy_access_node_access_update($affected_nodes);
}
}
else {
node_access_needs_rebuild(TRUE);
}
break;
}
return;
}