Commit 758a81e6 authored by catch's avatar catch

Issue #2473021 by jcnventura, amitgoyal: Deprecate...

Issue #2473021 by jcnventura, amitgoyal: Deprecate NodeAccessControlHandlerInterface::writeGrants() for removal in Drupal 9.0.x
parent f7b30ad6
......@@ -151,7 +151,6 @@ function hook_node_grants(\Drupal\Core\Session\AccountInterface $account, $op) {
* @return
* An array of grants as defined above.
*
* @see node_access_write_grants()
* @see hook_node_access_records_alter()
* @ingroup node_access
*/
......
......@@ -1133,6 +1133,7 @@ function node_access_needs_rebuild($rebuild = NULL) {
*/
function node_access_rebuild($batch_mode = FALSE) {
$node_storage = \Drupal::entityManager()->getStorage('node');
/** @var \Drupal\node\NodeAccessControlHandlerInterface $access_control_handler */
$access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node');
$access_control_handler->deleteGrants();
// Only recalculate if the site is using a node_access module.
......@@ -1162,7 +1163,8 @@ function node_access_rebuild($batch_mode = FALSE) {
// To preserve database integrity, only write grants if the node
// loads successfully.
if (!empty($node)) {
$access_control_handler->writeGrants($node);
$grants = $access_control_handler->acquireGrants($node);
\Drupal::service('node.grant_storage')->write($node, $grants);
}
}
}
......@@ -1212,7 +1214,10 @@ function _node_access_rebuild_batch_operation(&$context) {
// To preserve database integrity, only write grants if the node
// loads successfully.
if (!empty($node)) {
\Drupal::entityManager()->getAccessControlHandler('node')->writeGrants($node);
/** @var \Drupal\node\NodeAccessControlHandlerInterface $access_control_handler */
$access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node');
$grants = $access_control_handler->acquireGrants($node);
\Drupal::service('node.grant_storage')->write($node, $grants);
}
$context['sandbox']['progress']++;
$context['sandbox']['current_node'] = $nid;
......
......@@ -131,7 +131,10 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) {
// default revision. There's no need to delete existing records if the node
// is new.
if ($this->isDefaultRevision()) {
\Drupal::entityManager()->getAccessControlHandler('node')->writeGrants($this, $update);
/** @var \Drupal\node\NodeAccessControlHandlerInterface $access_control_handler */
$access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node');
$grants = $access_control_handler->acquireGrants($this);
\Drupal::service('node.grant_storage')->write($this, $grants, NULL, $update);
}
// Reindex the node when it is updated. The node is automatically indexed
......
......@@ -35,13 +35,11 @@ public function acquireGrants(NodeInterface $node);
/**
* Writes a list of grants to the database, deleting any previously saved ones.
*
* If a realm is provided, it will only delete grants from that realm, but it
* will always delete a grant from the 'all' realm. Modules that use node
* access can use this function when doing mass updates due to widespread
* permission changes.
* 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
* node_access_acquire_grants() instead.
* \Drupal\node\NodeAccessControlHandlerInterface::acquireGrants() instead.
*
* @param \Drupal\node\NodeInterface $node
* The node whose grants are being written.
......@@ -49,6 +47,9 @@ public function acquireGrants(NodeInterface $node);
* (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);
......
......@@ -61,7 +61,7 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account
* permission changes.
*
* Note: Don't call this method directly from a contributed module. Call
* node_access_write_grants() instead.
* \Drupal\node\NodeAccessControlHandlerInterface::acquireGrants() instead.
*
* @param \Drupal\node\NodeInterface $node
* The node whose grants are being written.
......@@ -78,9 +78,6 @@ public function alterQuery($query, array $tables, $op, AccountInterface $account
* (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.
*
* @see node_access_write_grants()
* @see node_access_acquire_grants()
*/
public function write(NodeInterface $node, array $grants, $realm = NULL, $delete = TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment