function node_access_view_all_nodes
Same name in other branches
- 7.x modules/node/node.module \node_access_view_all_nodes()
- 9 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: (optional) The user object for the user whose access is being checked. If omitted, the current user is used. Defaults to NULL.
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()
- NodeAccessGrantsCacheContext::checkNodeGrants in core/
modules/ node/ src/ Cache/ NodeAccessGrantsCacheContext.php - Checks the node grants for the given operation.
- node_query_node_access_alter in core/
modules/ node/ node.module - Implements hook_query_TAG_alter().
2 string references to 'node_access_view_all_nodes'
- NodeAccessGrantsCacheContextTest::testCacheContext in core/
modules/ node/ tests/ src/ Functional/ NodeAccessGrantsCacheContextTest.php - Tests NodeAccessGrantsCacheContext::getContext().
- NodeQueryAlterTest::testNodeQueryAlterOverride in core/
modules/ node/ tests/ src/ Functional/ NodeQueryAlterTest.php - Tests 'node_access' query alter override.
File
-
core/
modules/ node/ node.module, line 1084
Code
function node_access_view_all_nodes($account = NULL) {
if (!$account) {
$account = \Drupal::currentUser();
}
// Statically cache results in an array keyed by $account->id().
$access =& drupal_static(__FUNCTION__);
if (isset($access[$account->id()])) {
return $access[$account->id()];
}
// If no modules implement the node access system, access is always TRUE.
if (!\Drupal::moduleHandler()->getImplementations('node_grants')) {
$access[$account->id()] = TRUE;
}
else {
$access[$account->id()] = \Drupal::entityTypeManager()->getAccessControlHandler('node')
->checkAllGrants($account);
}
return $access[$account->id()];
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.