function taxonomy_access_query_term_access_alter in Taxonomy Access Control 7
Implements hook_query_TAG_alter() for 'term_access'.
Provides sitewide list grant filtering, as well as create grant filtering for autocomplete paths.
@todo Fix create permission filtering for autocomplete paths.
Related topics
File
- ./
taxonomy_access.module, line 312 - Allows administrators to specify access control for taxonomy categories.
Code
function taxonomy_access_query_term_access_alter($query) {
// Take no action while the list op is disabled.
if (!taxonomy_access_list_enabled()) {
return;
}
// Take no action if there is no term table in the query.
$alias = '';
$tables =& $query
->getTables();
foreach ($tables as $i => $table) {
if (strpos($table['table'], 'taxonomy_term_') === 0) {
$alias = $table['alias'];
}
}
if (empty($alias)) {
return;
}
// Fetch a list of all terms the user may list.
$tids =& drupal_static(__FUNCTION__, taxonomy_access_user_list_terms());
// If exactly TRUE was returned, the user can list all terms.
if ($tids === TRUE) {
return;
}
// If the user cannot list any terms, then allow only null values.
if (empty($tids)) {
$query
->isNull($alias . ".tid");
}
else {
$query
->condition($alias . ".tid", $tids, "IN");
}
}