function nodeaccess_insert_userreference in Nodeaccess 6
Same name and namespace in other branches
- 6.2 nodeaccess.module \nodeaccess_insert_userreference()
Insert userreference grants from a node.
Parameters
$node: The node with enabled userreference grants to insert.
1 call to nodeaccess_insert_userreference()
- nodeaccess_nodeapi in ./
nodeaccess.module - Implementation of hook_nodeapi().
File
- ./
nodeaccess.module, line 852
Code
function nodeaccess_insert_userreference($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 . '_userreference', array());
foreach ($fields as $field_name => $field) {
foreach ($node->{$field_name} as $values) {
// Add the settings for this UID. If the UID is zero, then the
// userreference field is set to None.
if ($values['uid'] > 0) {
$user = user_load($values['uid']);
$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);
}
}