- 🇦🇺Australia acbramley
writeGrants and node_access_write_grants are now gone.
The acquireGrants seem to make sense, so closing this as outdated. Please feel free to reopen and rescope the issue if you disagree.
We're still suffering from a 10 year old confusion here...
#2473021: Deprecate NodeAccessControlHandlerInterface::writeGrants() for removal in Drupal 9.0.x → has raised the confusion level again significantly — we currently have the following (merging NodeAccessControlHandlerInterface and NodeAccessControlHandler):
/**
* Gets the list of node access grants.
*
* This function is called to check the access grants for a node. It collects
* all node access grants for the node from hook_node_access_records()
* implementations, allows these grants to be altered via
* hook_node_access_records_alter() implementations, and returns the grants to
* the caller.
*
* @param \Drupal\node\NodeInterface $node
* The $node to acquire grants for.
*
* @return array $grants
* The access rules for the node.
*/
public function acquireGrants(NodeInterface $node) {
$grants = $this->moduleHandler->invokeAll('node_access_records', array($node));
// Let modules alter the grants.
$this->moduleHandler->alter('node_access_records', $grants, $node);
// If no grants are set and the node is published, then use the default grant.
if (empty($grants) && $node->isPublished()) {
$grants[] = array('realm' => 'all', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
}
return $grants;
}
/**
* Writes a list of grants to the database, deleting any previously saved ones.
*
* Modules that use node access can use this function when doing mass updates
* due to widespread permission changes.
*
* Note: Don't call this function directly from a contributed module. Call
* \Drupal\node\NodeAccessControlHandlerInterface::acquireGrants() instead.
*
* @param \Drupal\node\NodeInterface $node
* The node whose grants are being written.
* @param $delete
* (optional) If false, does not delete records. This is only for optimization
* purposes, and assumes the caller has already performed a mass delete of
* some form. Defaults to TRUE.
*
* @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
* Use \Drupal\node\NodeAccessControlHandlerInterface::acquireGrants().
*/
public function writeGrants(NodeInterface $node, $delete = TRUE) {
$grants = $this->acquireGrants($node);
$this->grantStorage->write($node, $grants, NULL, $delete);
}
acquireGrants()
just returns the grant records, but it doesn't do anything in the database. Calling it "instead" does not work!
writeGrants()
calls acquireGrants()
and then writes them to the database. It is the one that everyone needs to call, even though it's deprecated and its docblock says "Don't call this function". Core (and probably everyone else) works around this contradiction by just copying the two lines in writeGrants()
, which is obviously stupid.
acquireGrants()
, OTOH, is only useful if you're going to write those grant records, which is precisely what writeGrants()
does. There's one exception: Devel Node Access would like to call acquireGrants()
in order to verify that what's in the node_access table is actually correct.
Closed: outdated
11.0 🔥
node system
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
writeGrants and node_access_write_grants are now gone.
The acquireGrants seem to make sense, so closing this as outdated. Please feel free to reopen and rescope the issue if you disagree.