Quantcast
Channel: Active questions tagged users - Drupal Answers
Viewing all articles
Browse latest Browse all 451

Is there a way to add node grants to anonymous users?

$
0
0

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(\Drupal\Core\Session\AccountInterface $account, $op) {   return ['show_promoted_news' => [9999]];}function myModule_node_access_records(\Drupal\node\NodeInterface $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().


Viewing all articles
Browse latest Browse all 451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>