function tac_lite_node_access_records in Taxonomy Access Control Lite 8
Same name and namespace in other branches
- 5 tac_lite.module \tac_lite_node_access_records()
- 6 tac_lite.module \tac_lite_node_access_records()
- 7 tac_lite.module \tac_lite_node_access_records()
Implements hook_node_access_records().
File
- ./
tac_lite.module, line 54 - Control access to site content based on taxonomy, roles and users.
Code
function tac_lite_node_access_records(NodeInterface $node) {
$tids = _tac_lite_get_terms($node);
if (count($tids)) {
// If we're here, the node has terms associated with it which restrict
// access to the node.
$grants = [];
$settings = \Drupal::config('tac_lite.settings');
$schemes = $settings
->get('tac_lite_schemes');
for ($i = 1; $i <= $schemes; $i++) {
$config = SchemeForm::tacLiteConfig($i);
// Only apply grants to published nodes, or unpublished nodes
// if requested in the scheme.
if ($node
->isPublished() || $config['unpublished']) {
foreach ($tids as $tid) {
$grant = [
'realm' => $config['realm'],
// Use term id as grant id.
'gid' => $tid,
'grant_view' => 0,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 0,
];
foreach ($config['perms'] as $perm) {
$grant[$perm] = 1;
}
$grants[] = $grant;
}
}
}
return $grants;
}
}