function NodeAccessTestHooks::nodeAccessRecords
Implements hook_node_access_records().
By default, records are written for all nodes. When the 'node_access_test.private' state variable is set to TRUE, records are only written for nodes with a "private" property set, which causes the Node module to write the default global view grant for nodes that are not marked private.
See also
\Drupal\node\Tests\NodeAccessBaseTableTest::setUp()
node_access_test_node_grants()
node_access_test.permissions.yml
File
-
core/
modules/ node/ tests/ modules/ node_access_test/ src/ Hook/ NodeAccessTestHooks.php, line 68
Class
- NodeAccessTestHooks
- Hook implementations for node_access_test.
Namespace
Drupal\node_access_test\HookCode
public function nodeAccessRecords(NodeInterface $node) : array {
$grants = [];
// For NodeAccessBaseTableTestCase, only set records for private nodes.
if (!\Drupal::state()->get('node_access_test.private') || isset($node->private) && $node->private->value) {
// Groups 8888 and 8889 for the node_access_test realm both receive a view
// grant for all controlled nodes. See node_access_test_node_grants().
$grants[] = [
'realm' => 'node_access_test',
'gid' => 8888,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
];
$grants[] = [
'realm' => 'node_access_test',
'gid' => 8889,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
];
// For the author realm, the group ID is equivalent to a user ID, which
// means there are many groups of just 1 user.
$grants[] = [
'realm' => 'node_access_test_author',
'gid' => $node->getOwnerId(),
'grant_view' => 1,
'grant_update' => 1,
'grant_delete' => 1,
];
}
return $grants;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.