I have a site where I work with main users and sub users (users created by a main user). Using permissions I allow these users to edit other users nodes.
Using a script inside hook_node_access
I make sure access is only allowed for users that are related to each other.
The stripped version of my code looks something like:
hook_node_access(NodeInterface $node, $op, $account){
if ($op == 'update') {
$uids = [1,2,3,4] //array of user ids related to each other
// when node author is not in user id array...forbid access
return AccessResult::forbiddenIf(!in_array($account->id(), $uids))->cachePerUser()->addCacheableDependency($node);
}
}
This works but when a none author tries to edit a unpublished node I get an error.
The path 'node/x' is either invalid or you do not have access to it.
What can I do to give a none author update access to a unpublished node?