From 758a81e61d0df5098ed398936f37f95493df02f2 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Wed, 13 Jan 2016 15:07:32 +0900 Subject: [PATCH] Issue #2473021 by jcnventura, amitgoyal: Deprecate NodeAccessControlHandlerInterface::writeGrants() for removal in Drupal 9.0.x --- core/modules/node/node.api.php | 1 - core/modules/node/node.module | 9 +++++++-- core/modules/node/src/Entity/Node.php | 5 ++++- .../node/src/NodeAccessControlHandlerInterface.php | 11 ++++++----- .../node/src/NodeGrantDatabaseStorageInterface.php | 5 +---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/core/modules/node/node.api.php b/core/modules/node/node.api.php index 2479a2996d..af07dff91e 100644 --- a/core/modules/node/node.api.php +++ b/core/modules/node/node.api.php @@ -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 */ diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 91d27e8837..112e9df827 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -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; diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 118e86252d..cd9b4e51a5 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -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 diff --git a/core/modules/node/src/NodeAccessControlHandlerInterface.php b/core/modules/node/src/NodeAccessControlHandlerInterface.php index 9e7c34af6c..0b629d7c84 100644 --- a/core/modules/node/src/NodeAccessControlHandlerInterface.php +++ b/core/modules/node/src/NodeAccessControlHandlerInterface.php @@ -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); diff --git a/core/modules/node/src/NodeGrantDatabaseStorageInterface.php b/core/modules/node/src/NodeGrantDatabaseStorageInterface.php index c59f941232..9a2586f0f4 100644 --- a/core/modules/node/src/NodeGrantDatabaseStorageInterface.php +++ b/core/modules/node/src/NodeGrantDatabaseStorageInterface.php @@ -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); -- GitLab