function _jeditable_save_userreference_field in jEditable inline content editing 6
Same name and namespace in other branches
- 6.2 jeditable.module \_jeditable_save_userreference_field()
Helper function to save userreference field.
Parameters
$node: The node to act on.
$field: The user reference field to act on.
$value: The UID of the selected user.
Return value
The value that was actually saved in the field.
1 call to _jeditable_save_userreference_field()
- _jeditable_ajax_save in ./
jeditable.module - Helper function to save a value using the jeditable callback
File
- ./
jeditable.module, line 298 - jeditable.module
Code
function _jeditable_save_userreference_field($node, $field, $value) {
module_load_include('inc', 'node', 'node.pages');
$field_name = $field['field_name'];
$form_state = array();
$form_state['values'][$field_name]['uid']['uid'] = $value;
$form_state['values']['op'] = t('Save');
$form_id = $node->type . '_node_form';
drupal_execute($form_id, &$form_state, (object) $node);
drupal_get_messages('status');
// Discard status messages
// @todo: Do some Ajax with the warning and error messages.
//$messages = drupal_get_messages();
// Reload the node to get the value that was saved, if any. Avoid the cache.
$node = node_load(array(
"nid" => $node->nid,
));
if (isset($node->{$field_name})) {
$value = $node->{$field_name}[0]['uid'];
}
else {
$value = NULL;
}
$referenced_user = user_load(array(
'uid' => $value,
));
$value = $referenced_user->name;
// @todo: Should content_format be called here?
return $value;
}