function node_access_view_all_nodes
Same name in other branches
- 9 core/modules/node/node.module \node_access_view_all_nodes()
- 8.9.x core/modules/node/node.module \node_access_view_all_nodes()
- 10 core/modules/node/node.module \node_access_view_all_nodes()
- 11.x core/modules/node/node.module \node_access_view_all_nodes()
Determines whether the user has a global viewing grant for all nodes.
Checks to see whether any module grants global 'view' access to a user account; global 'view' access is encoded in the {node_access} table as a grant with nid=0. If no node access modules are enabled, node.module defines such a global 'view' access grant.
This function is called when a node listing query is tagged with 'node_access'; when this function returns TRUE, no node access joins are added to the query.
Parameters
$account: The user object for the user whose access is being checked. If omitted, the current user is used.
Return value
TRUE if 'view' access to all nodes is granted, FALSE otherwise.
See also
_node_query_node_access_alter()
Related topics
2 calls to node_access_view_all_nodes()
- hook_query_TAG_alter in modules/
system/ system.api.php - Perform alterations to a structured query for a given tag.
- _node_query_node_access_alter in modules/
node/ node.module - Helper for node access functions.
2 string references to 'node_access_view_all_nodes'
- entity_query_access_test_sample_query in modules/
simpletest/ tests/ entity_query_access_test.module - Returns the results from an example EntityFieldQuery.
- NodeQueryAlter::testNodeQueryAlterOverride in modules/
node/ node.test - Tests 'node_access' query alter override.
File
-
modules/
node/ node.module, line 3251
Code
function node_access_view_all_nodes($account = NULL) {
global $user;
if (!$account) {
$account = $user;
}
// Statically cache results in an array keyed by $account->uid.
$access =& drupal_static(__FUNCTION__);
if (isset($access[$account->uid])) {
return $access[$account->uid];
}
// If no modules implement the node access system, access is always TRUE.
if (!module_implements('node_grants')) {
$access[$account->uid] = TRUE;
}
else {
$query = db_select('node_access');
$query->addExpression('COUNT(*)');
$query->condition('nid', 0)
->condition('grant_view', 1, '>=');
$grants = node_add_node_grants_to_query(node_access_grants('view', $account));
if (count($grants) > 0) {
$query->condition($grants);
}
$access[$account->uid] = $query->execute()
->fetchField();
}
return $access[$account->uid];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.