function node_registration_node_access in Node registration 7
Implements hook_node_access().
Ignores existing node access permissions and creates a few new.
10 calls to node_registration_node_access()
- node_registration_access in includes/
node_registration.api.inc - All Registration access callbacks. Just like node.module has node_access.
- node_registration_block_view in ./
node_registration.module - Implements hook_block_view().
- node_registration_entity_view in ./
node_registration.module - Implements hook_entity_view().
- node_registration_form in includes/
node_registration.forms.inc - The registration form. It takes a (mandatory) existing or empty registration object.
- node_registration_form_node_form_alter in ./
node_registration.module - Implements hook_form_FORM_ID_alter() for node_form().
3 string references to 'node_registration_node_access'
- node_registration_menu in ./
node_registration.module - Implements hook_menu().
- node_registration_menu_alter in ./
node_registration.module - Implements hook_menu_alter().
- node_registration_preprocess_page in ./
node_registration.module - Implements hook_preprocess_page().
File
- includes/
node_registration.api.inc, line 322 - Registration API functions.
Code
function node_registration_node_access($node, $op, $account = NULL, &$reason = NULL) {
if (!in_array($op, array(
'register',
'register others',
'administer',
'registered',
'registration settings',
))) {
return;
}
global $user;
$account or $account = $user;
if (!is_object($node)) {
$node = node_load((string) $node);
if (!is_object($node)) {
return;
}
}
$nid = empty($node->nid) ? 0 : $node->nid;
$nid_key = $nid ?: $node->type;
$reasons =& drupal_static(__FUNCTION__ . ':reasons');
$cache_key = __FUNCTION__ . ':' . $nid_key . ':' . $op . ':' . $account->uid;
$access = _node_registration_cache($cache_key, function () use ($cache_key, $node, $nid, $op, $account, &$reason) {
switch ($op) {
case 'register':
$registration = entity_get_controller('node_registration')
->create(array(
'nid' => $nid,
));
return node_registration_access($registration, 'add', $account, $reason);
break;
case 'register others':
return user_access('other node registration', $account) || node_registration_node_access($node, 'administer');
break;
case 'administer':
return user_access('administer node registration', $account);
break;
case 'registered':
return ($registration = _node_registration_user_registered($node, $account)) && node_registration_access($registration, 'view', $account, $reason);
break;
case 'registration settings':
return _node_registration_node_type_enabled($node->type) && user_access('administer node registration', $account);
break;
}
return FALSE;
}, function ($result, $cache_key) use ($node, $op, $account, &$reason) {
// Allow other modules to override and change this result.
$reason or $reason = $result ? '' : '?';
$alt_access = module_invoke_all('node_registration_node_access', $node, $op, $account, $reason);
if (in_array(!$result, $alt_access, TRUE)) {
return !$result;
}
return $result;
});
if ($reason) {
$reasons[$cache_key] = $reason;
}
else {
$reason = @$reasons[$cache_key];
}
return $access;
}