- π¦πΊAustralia acbramley
From NodeAccessControlHandlerInterface::acquireGrants documentation we have
hook_node_access_records
andhook_node_access_records_alter
is this sufficient? - πΊπΈUnited States bkosborne New Jersey, USA
Unfortunately, no. This issue is about node grants, not node access records. Grants are what define the access rules for a node, and access records are what assign individual users the keys to unlock those grants. What we need here is the ability to hook into the process when node access grants are rebuilt, which doesn't exist.
I created this issue 7 years ago, and I clearly found some kind of workaround, I just don't know what it is!
- Status changed to Active
about 1 month ago 1:17am 4 July 2025 - πΊπΈUnited States xjm
The issue closed as a duplicate proposed adding a new hook, with the following patch (this won't apply; it was from 2017):
diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 604187406b..3f0fcd1756 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -236,6 +236,26 @@ function hook_node_access_records_alter(&$grants, Drupal\node\NodeInterface $nod } /** + * Acts when saving node access records. + * + * This hook runs after node access records were saved. + * + * @param array $grants + * The saved grants. + * @param \Drupal\node\NodeInterface $node + * The node for which the grants were saved. + * + * @see hook_node_access_records() + * @see hook_node_access_records_alter() + * @see hook_node_grants() + * @see hook_node_grants_alter() + * @ingroup node_access + */ +function hook_node_access_records_save($grants, Drupal\node\NodeInterface $node) { + mymodule_node_access_records_saving_reaction($node, $grants); +} + +/** * Alter user access rules when trying to view, edit or delete a node. * * Node access modules establish rules for user access to content. diff --git a/core/modules/node/src/NodeGrantDatabaseStorage.php b/core/modules/node/src/NodeGrantDatabaseStorage.php index 993d0950d1..73dbca7259 100644 --- a/core/modules/node/src/NodeGrantDatabaseStorage.php +++ b/core/modules/node/src/NodeGrantDatabaseStorage.php @@ -238,6 +238,9 @@ public function write(NodeInterface $node, array $grants, $realm = NULL, $delete } } $query->execute(); + + // Let modules react for grants saving. + $this->moduleHandler->invokeAll('node_access_records_save', [$grants, $node]); } }
That's a legacy pattern, but this does seem like a reasonable feature request in concept.
- First commit to issue fork.