I want anonymous users to be able to access nodes that are promoted to the front page. (They can’t access to nodes that are not promoted.) It seems hook_node_access()
isn’t seem called for anonymous users. I tried using hook_node_grants()
and hook_node_access_records()
, but the code I am using doesn’t seem to give anonymous users access to nodes promoted to front page.
function myModule_node_grants(DrupalCoreSessionAccountInterface $account, $op) { return ['show_promoted_news' => [9999]]; } function myModule_node_access_records(DrupalnodeNodeInterface $node) { $grants = []; if ($node->isPublished() and $node->isPromoted() and $node->getType() == 'article') { $grants[] = [ 'realm' => 'show_promoted_news', 'gid' => 9999, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0, 'langcode' => 'en' ]; } return $grants; }
The access content permission is overriding the grants I give to the anonymous users, who can’t access published content. Adding a greater priority does nothing.
I’m being forced to allow anonymous users to access content and override that when I don’t want them to have access with hook_node_access()
.