Skip to main content
expanded the answer
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

The infinite loop you are noticing is caused from the fact that menu_get_object() causes Drupal to verify the currently logged-in user has access to the node, which causes your implementation of hook_node_grants() to be invoked again, which calls menu_get_object(), which causes your implementation of hook_node_grants() to be invoked again, which….

It is hook_node_access_records() that has access to the node object; the code you are using in hook_node_grants() should be used in hook_node_access_records().

See Node access rights for more information. In short, hook_node_grants() returns a realm => GID array, while hook_node_access_records() return an array containing realm, GID, priority, and three 0/1 values for the view/update/delete permissions the current user has.

The infinite loop you are noticing is caused from the fact that menu_get_object() causes Drupal to verify the currently logged-in user has access to the node, which causes your implementation of hook_node_grants() to be invoked again, which calls menu_get_object(), which causes your implementation of hook_node_grants() to be invoked, which….

It is hook_node_access_records() that has access to the node object; the code you are using in hook_node_grants() should be used in hook_node_access_records().

The infinite loop you are noticing is caused from the fact that menu_get_object() causes Drupal to verify the currently logged-in user has access to the node, which causes your implementation of hook_node_grants() to be invoked again, which calls menu_get_object(), which causes your implementation of hook_node_grants() to be invoked again, which….

It is hook_node_access_records() that has access to the node object; the code you are using in hook_node_grants() should be used in hook_node_access_records().

See Node access rights for more information. In short, hook_node_grants() returns a realm => GID array, while hook_node_access_records() return an array containing realm, GID, priority, and three 0/1 values for the view/update/delete permissions the current user has.

Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

The infinite loop you are noticing is caused from the fact that menu_get_object() causes Drupal to verify the currently logged-in user has access to the node, which causes your implementation of hook_node_grants() to be invoked again, which calls menu_get_object(), which causes your implementation of hook_node_grants() to be invoked, which….

It is hook_node_access_records() that has access to the node object; the code you are using in hook_node_grants() should be used in hook_node_access_records().