function content_access_get_type_grant in Content Access 8
Same name and namespace in other branches
- 6 content_access.module \content_access_get_type_grant()
- 7 content_access.module \content_access_get_type_grant()
Returns the default grants for a given node type.
1 call to content_access_get_type_grant()
- content_access_node_access_records in ./
content_access.module - Implements hook_node_access_records().
File
- ./
content_access.module, line 336 - Content access module file.
Code
function content_access_get_type_grant(NodeInterface $node) {
// Cache per type default grants in a static array.
static $defaults = [];
$node_type = $node
->getType();
if (!isset($defaults[$node_type])) {
$grants = [];
// Only process the 'view' op as node_access() will take care of
// edit and delete.
foreach (content_access_get_settings('view', $node_type) as $rid) {
$gid = content_access_get_role_gid($rid);
$grant['grant_view'] = 1;
$grants[] = content_access_proccess_grant($grant, $gid, $node);
}
$defaults[$node_type] = $grants;
}
// Care for the author grant.
$grant = $grants = [];
$settings = [
'view' => content_access_get_settings('view', $node_type),
'view_own' => content_access_get_settings('view_own', $node_type),
];
$grant['grant_view'] = content_access_own_op($node, $settings['view'], $settings['view_own']);
if ($grant['grant_view']) {
$grant['realm'] = 'content_access_author';
$grants = [
'author' => content_access_proccess_grant($grant, $node
->getOwnerId(), $node),
];
}
return $defaults[$node_type] + $grants;
}