function tac_lite_node_access_records in Taxonomy Access Control Lite 7
Same name and namespace in other branches
- 8 tac_lite.module \tac_lite_node_access_records()
- 5 tac_lite.module \tac_lite_node_access_records()
- 6 tac_lite.module \tac_lite_node_access_records()
Implements hook_node_access_records().
We are given a node and we return records for the node_access table. In our case, we inpect the node's taxonomy and grant permissions based on the terms.
File
- ./
tac_lite.module, line 464 - Control access to site content based on taxonomy, roles and users.
Code
function tac_lite_node_access_records($node) {
// Get the tids we care about that are assigned to this node
$tids = _tac_lite_get_terms($node);
if (!count($tids)) {
// no relevant terms found.
// in drupal 4-7 we had to write a row into the database. In drupal 5 and later, it should be safe to do nothing.
}
else {
// if we're here, the node has terms associated with it which restrict
// access to the node.
$grants = array();
for ($i = 1; $i <= variable_get('tac_lite_schemes', 1); $i++) {
$config = _tac_lite_config($i);
// Only apply grants to published nodes, or unpublished nodes if requested in the scheme
if ($node->status || $config['unpublished']) {
foreach ($tids as $tid) {
$grant = array(
'realm' => $config['realm'],
'gid' => $tid,
// use term id as grant id
'grant_view' => 0,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
);
foreach ($config['perms'] as $perm) {
$grant[$perm] = TRUE;
}
$grants[] = $grant;
}
}
}
return $grants;
}
}