You are here

function _jeditable_save_nodereference_field in jEditable inline content editing 6.2

Same name and namespace in other branches
  1. 6 jeditable.module \_jeditable_save_nodereference_field()

Helper function to save nodereference field.

Parameters

$node: The node to act on.

$field: An array containing the field properties.

$value: The NID of the selected node.

Return value

The value that was actually saved in the field.

1 call to _jeditable_save_nodereference_field()
_jeditable_ajax_save in ./jeditable.module
Helper function to save a value using the jeditable callback.

File

./jeditable.module, line 244

Code

function _jeditable_save_nodereference_field($node, $field, $value) {
  module_load_include('inc', 'node', 'node.pages');
  $field_name = $field['field_name'];
  $form_state = array();
  $form_state['values'][$field_name]['nid']['nid'] = $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]['nid'];
  }
  else {
    $value = NULL;
  }
  $referenced_node = node_load($value);
  $value = $referenced_node->title;

  // @todo: Should content_format be called here?
  return $value;
}