You are here

function _jeditable_save_nodereference_field in jEditable inline content editing 6

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

Helper function to save nodereference 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 254
jeditable.module

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;
}