function NodeTestHooks::nodeAccessRecords

Implements hook_node_access_records().

File

core/modules/node/tests/modules/node_test/src/Hook/NodeTestHooks.php, line 77

Class

NodeTestHooks
Hook implementations for node_test.

Namespace

Drupal\node_test\Hook

Code

public function nodeAccessRecords(NodeInterface $node) {
    // Return nothing when testing for empty responses.
    if (!empty($node->disable_node_access)) {
        return;
    }
    $grants = [];
    if ($node->getType() == 'article') {
        // Create grant in arbitrary article_realm for article nodes.
        $grants[] = [
            'realm' => 'test_article_realm',
            'gid' => 1,
            'grant_view' => 1,
            'grant_update' => 0,
            'grant_delete' => 0,
        ];
    }
    elseif ($node->getType() == 'page') {
        // Create grant in arbitrary page_realm for page nodes.
        $grants[] = [
            'realm' => 'test_page_realm',
            'gid' => 1,
            'grant_view' => 1,
            'grant_update' => 0,
            'grant_delete' => 0,
        ];
    }
    return $grants;
}

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