diff -u b/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php --- b/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -22,7 +22,7 @@ /** * Defines the access controller for the node entity type. */ -class NodeAccessController extends EntityAccessController implements EntityControllerInterface { +class NodeAccessController extends EntityAccessController implements NodeAccessControllerInterface, EntityControllerInterface { /** * The node grant storage. @@ -31,14 +31,22 @@ */ protected $grantStorage; + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + /** * Constructs a NodeAccessController object. * * @param \Drupal\node\NodeGrantStorageControllerInterface $grant_storage * The node grant storage. */ - public function __construct(NodeGrantStorageControllerInterface $grant_storage) { - $this->grantStorage = $grant_storage; + public function __construct(NodeGrantStorageControllerInterface $grant_storage, ModuleHandlerInterface $module_handler) { + $this->grantStorage = $grant_storage; + $this->moduleHandler = $module_handler; } /** @@ -46,7 +54,8 @@ */ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { return new static( - $container->get('plugin.manager.entity')->getController('node', 'grant_storage') + $container->get('plugin.manager.entity')->getController('node', 'grant_storage'), + $container->get('module_handler') ); } @@ -100,2 +109,24 @@ + /** + * {@inheritdoc} + */ + 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; + } + + /** + * {@inheritdoc} + */ + public function writeGrants(NodeInterface $node, $delete = TRUE) { + $grants = $this->acquireGrants($node); + $this->grantStorage->nodeAccessWriteGrants($node, $grants, NULL, $delete); + } + } diff -u b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php --- b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/Core/Entity/Node.php @@ -116,7 +116,7 @@ // default revision. There's no need to delete existing records if the node // is new. if ($this->isDefaultRevision()) { - node_access_write_grants($this->getBCEntity(), $update); + \Drupal::entityManager()->getAccessController('node')->writeGrants($this->getBCEntity(), $update); } } diff -u b/core/modules/node/node.module b/core/modules/node/node.module --- b/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -2435,54 +2434,0 @@ - * 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. - * @param bool $delete - * (optional) Whether to delete existing node access records before inserting - * new ones. Defaults to TRUE. - * - * @return array $grants - * The access rules for the node. - */ -function node_access_acquire_grants(NodeInterface $node, $delete = TRUE) { - $grants = module_invoke_all('node_access_records', $node); - // Let modules alter the grants. - drupal_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; -} - -/** - * 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\Core\Entity\EntityInterface $node - * The $node to acquire grants for. - * @param $delete - * (optional) Whether to delete existing node access records before inserting - * new ones. Defaults to TRUE. - * - * @return array $grants - * The access rules for the node. - * - * @see node_access_acquire_grants() - */ -function node_access_write_grants(EntityInterface $node, $delete = TRUE) { - $grants = node_access_acquire_grants($node); - Drupal::entityManager()->getController('node', 'grant_storage')->nodeAccessWriteGrants($node, $grants, NULL, $delete); -} - -/** @@ -2567,7 +2513,7 @@ // To preserve database integrity, only write grants if the node // loads successfully. if (!empty($node)) { - node_access_write_grants($node); + Drupal::entityManager()->getAccessController('node')->writeGrants($node); } } } @@ -2614,7 +2560,7 @@ // To preserve database integrity, only write grants if the node // loads successfully. if (!empty($node)) { - node_access_write_grants($node); + Drupal::entityManager()->getAccessController('node')->writeGrants($node); } $context['sandbox']['progress']++; $context['sandbox']['current_node'] = $nid; only in patch2: unchanged: --- /dev/null +++ b/core/modules/node/lib/Drupal/node/NodeAccessControllerInterface.php @@ -0,0 +1,50 @@ +