We implemented hook_access_grants in our own module, and have a role set to having the permission 'view own unpublished content'. Our hook_node_access_records doesn't return any realms or gids if particular conditions are met on a node (In this case we want to fall back onto the normal access system, so ignoring our own implementation).
When a user with role in question now creates a node (that meets these particular conditions so no acces records are provided) and saves this node unpublished, the user cannot see the node in the content overview page.
When implementing the hook, is it normal that in NodeAccessControlHandler::checkAccess is never called when implementing the access_grants hook?
This code is never executed when we enable our module (implementing hook_access_grants):
protected function checkAccess(EntityInterface $node, $operation, AccountInterface $account) {
/** @var \Drupal\node\NodeInterface $node */
// Fetch information from the node object if possible.
$status = $node->isPublished();
$uid = $node->getOwnerId();
// Check if authors can view their own unpublished nodes.
if ($operation === 'view' && !$status && $account->hasPermission('view own unpublished content') && $account->isAuthenticated() && $account->id() == $uid) {
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($node);
}
// Evaluate node grants.
return $this->grantStorage->access($node, $operation, $account);
}
Comments
Comment #9
cilefen CreditAttribution: cilefen commentedI am closing this support request because there have been no recent comments.
The Drupal Core issue queue is not the ideal place for support requests. Consider other sources of support.