function NodeTestHooks::nodeAccessRecordsAlter

Implements hook_node_access_records_alter().

File

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

Class

NodeTestHooks
Hook implementations for node_test.

Namespace

Drupal\node_test\Hook

Code

public function nodeAccessRecordsAlter(&$grants, NodeInterface $node) : void {
    if (!empty($grants)) {
        foreach ($grants as $key => $grant) {
            // Alter grant from test_page_realm to test_alter_realm and modify the gid.
            if ($grant['realm'] == 'test_page_realm' && $node->isPromoted()) {
                $grants[$key]['realm'] = 'test_alter_realm';
                $grants[$key]['gid'] = 2;
            }
        }
    }
}

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