Call hook_node_access_records() from custom function

Events happening in the community are now at Drupal community events on www.drupal.org.
DrupalCuckoo's picture

hi,

usually the hook "hook_node_access_records($node)" gets called when you hit the save-button on the edit page of a node. I need to call this function outside the edit-form.

I'm building a custom content-privacy module and I need to call this function for all existing nodes filtered by content-type (for example all blog nodes).

The problem I have is that this hook needs a node-object as a parameter. When being on a node-edit page (node/[NID]/edit) this object will be available. But when I don't edit a node I have no node-object available.

How can I create inside my module a node-object by myself to hand it over to the hook? I would need to create many node-object since I need to call this function for every existing node without going into each node to hit the save button on its edit page.

thanks for any help.

best regards.

Comments

.

DrupalCuckoo's picture

I've figured out that the hook "hook_node_access_records" save data into the node_access table.

Let's say I want to save node access data for all blog entries created by the admin user.

I would select all nodes from the node table which have the type=blog and the uid=1. Than I could save the nid of those nodes to the node_access table (with the same pattern from the hook_node_access_records function). Would this work?

Where is the realm field of the node_access table also needed? Can I to come up with anything or does this have to be something specific?

Problem solved!

DrupalCuckoo's picture

I solved the problem on my own. I'm not going to explain how I did it because I've no time right now but I will when I've got some spare time on my hands.

thanks anyway.

best regards.