function forum_access_access in Forum Access 8
Same name and namespace in other branches
- 5 forum_access.module \forum_access_access()
- 6 forum_access.module \forum_access_access()
- 7 forum_access.module \forum_access_access()
Access checking.
6 calls to forum_access_access()
- CommentForumFormatter::viewElements in src/
Plugin/ Field/ FieldFormatter/ CommentForumFormatter.php - Builds a renderable array for a field value.
- forum_access_comment_access in ./
forum_access.module - Implements hook_ENTITY_TYPE_access() for comment entities.
- forum_access_entity_access_by_tid in includes/
forum_access.common.inc - Check access for entity.
- forum_access_forum_check_view in includes/
forum_access.common.inc - Check access to view forums and containers.
- forum_access_node_create_access in ./
forum_access.module - Implements hook_ENTITY_TYPE_create_access() for node entities.
File
- includes/
forum_access.common.inc, line 46 - Handle common forum access functionality.
Code
function forum_access_access($op, $tid, $account = NULL) {
module_load_include('inc', 'forum_access', 'includes/forum_access.acl');
$cache =& drupal_static(__FUNCTION__, []);
// Load current user if account is empty.
if (!$account) {
$account = \Drupal::currentUser();
}
if ($account
->hasPermission('bypass node access')) {
return TRUE;
}
if ($op == 'delete' && $account
->hasPermission('delete any forum content')) {
return TRUE;
}
if ($op == 'update' && $account
->hasPermission('edit any forum content')) {
return TRUE;
}
if (!isset($cache[$account
->id()][$tid][$op])) {
// Check if user's roles allow him permissions to operators.
$query = \Drupal::database()
->select('forum_access', 'fa')
->fields('fa', [
'tid',
]);
forum_access_modify_check_query($query, [
'op' => $op,
'tid' => $tid,
]);
$query
->condition('fa.rid', $account
->getRoles(), 'IN');
$result = $query
->execute()
->fetchField();
if ($result) {
$cache[$account
->id()][$tid][$op] = TRUE;
}
else {
// Check our moderators too.
$acl_moderate = forum_access_is_moderator($account, $tid);
$cache[$account
->id()][$tid][$op] = !empty($acl_moderate);
}
}
return $cache[$account
->id()][$tid][$op];
}