function node_access_test_node_access_records

Same name in other branches
  1. 7.x modules/node/tests/node_access_test.module \node_access_test_node_access_records()
  2. 9 core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_node_access_records()
  3. 10 core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_node_access_records()
  4. 11.x core/modules/node/tests/modules/node_access_test/node_access_test.module \node_access_test_node_access_records()

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/node_access_test.module, line 79

Code

function node_access_test_node_access_records(NodeInterface $node) {
    $grants = [];
    // For NodeAccessBaseTableTestCase, only set records for private nodes.
    if (!\Drupal::state()->get('node_access_test.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,
            'priority' => 0,
        ];
        $grants[] = [
            'realm' => 'node_access_test',
            'gid' => 8889,
            'grant_view' => 1,
            'grant_update' => 0,
            'grant_delete' => 0,
            'priority' => 0,
        ];
        // For the author realm, the group ID is equivalent to a user ID, which
        // means there are many many groups of just 1 user.
        $grants[] = [
            'realm' => 'node_access_test_author',
            'gid' => $node->getOwnerId(),
            'grant_view' => 1,
            'grant_update' => 1,
            'grant_delete' => 1,
            'priority' => 0,
        ];
    }
    return $grants;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.