function forum_access_node_access in Forum Access 8
Same name and namespace in other branches
- 7 forum_access.module \forum_access_node_access()
Implements hook_node_access().
@inheritdoc
File
- ./
forum_access.module, line 79 - Contains forum_access.module.
Code
function forum_access_node_access(NodeInterface $node, $op, AccountInterface $account) {
if ($node
->bundle() != 'forum') {
return AccessResult::neutral();
}
// Disallow if user has no access to view.
module_load_include('inc', 'forum_access', 'includes/forum_access.common');
if (!forum_access_entity_access_by_tid('view', $node)) {
return AccessResult::forbidden();
}
$author = $node
->get('uid')
->first()
->get('entity')
->getTarget()
->getValue();
switch ($op) {
case 'view':
if ($node
->isPublished()) {
$access = forum_access_entity_access_by_tid($op, $node);
}
elseif ($author
->id() == $account
->id() && $account
->hasPermission('view own unpublished content')) {
$access = forum_access_entity_access_by_tid($op, $node);
}
break;
case 'update':
if ($op == 'update' && ($account
->hasPermission('edit any forum content') || $author
->id() == $account
->id() && $account
->hasPermission('edit own forum content'))) {
$access = forum_access_entity_access_by_tid('view', $node);
}
break;
case 'delete':
if ($op == 'delete' && ($account
->hasPermission('delete any forum content') || $author
->id() == $account
->id() && $account
->hasPermission('delete own forum content'))) {
$access = forum_access_entity_access_by_tid('view', $node);
}
break;
}
if (isset($access)) {
if ($access) {
return AccessResult::allowed();
}
else {
return AccessResult::forbidden();
}
}
return AccessResult::neutral();
}