function nodeaccess_insert_user_reference in Nodeaccess 7
Insert userreference grants from a node.
Parameters
Object $node:
1 call to nodeaccess_insert_user_reference()
- nodeaccess_node_update in ./
nodeaccess.module - Implements hook_node_update().
File
- ./
nodeaccess.module, line 882 - Provide per node access control
Code
function nodeaccess_insert_user_reference($node) {
$form_values = nodeaccess_get_grants($node);
// Now, append or overwrite the uid with what was specified in the user
// reference field.
$fields = variable_get('nodeaccess_' . $node->type . '_user_reference', array());
foreach ($fields as $field_name => $field) {
$user_uids = field_get_items('node', $node, $field_name);
$user_references = user_load_multiple($user_uids);
// Add each of the referenced users a form value.
foreach ($user_references as $user) {
$form_values['uid'][$user->uid] = array(
'name' => $user->name,
'keep' => 1,
'grant_view' => $field['grant_view'],
'grant_update' => $field['grant_update'],
'grant_delete' => $field['grant_delete'],
);
}
}
// Only do the changes if there are users to save.
if (count($form_values['uid']) > 0) {
$form_values['nid'] = $node->nid;
$form_state = array(
'values' => $form_values,
);
_nodeaccess_grants_form_submit(NULL, $form_state);
}
}