_node_resource_update

  1. services
    1. 7.3
    2. 7 node_resource.inc
    3. 6.2 node_resource.inc
    4. 6.3
Versions
6.3 – 7.3 _node_resource_update($nid, $node)

Updates a new node based on submitted values.

Note that this function uses drupal_execute() to create new nodes, which may require very specific formatting. The full implications of this are beyond the scope of this comment block. The Googles are your friend.

Parameters

$nid Node ID of the node we're editing.

$node Array representing the attributes a node edit form would submit.

Return value

The node's nid.

See also

drupal_execute()

Code

resources/node_resource.inc, line 307

<?php
function _node_resource_update($nid, $node) {
  // Adds backwards compatability with regression fixed in #1083242
  $node = _services_arg_value($node, 'node');

  $node['nid'] = $nid;

  $old_node = node_load($nid);
  node_object_prepare($old_node);

  // Validate the node. If there is validation error Exception will be thrown
  // so code below won't be executed.
  _node_resource_validate_type($node);

  if ($old_node->nid) {
    // Node types cannot be changed once they are created.
    if (isset($node['type']) && $node['type'] != $old_node->type) {
      return services_error(t('Node type cannot be changed'), 406);
    }

    // Load the required includes for drupal_execute
    module_load_include('inc', 'node', 'node.pages');

    $node_type = $node['type'];

    // Setup form_state.
    $form_state = array();
    $form_state['values'] = $node;
    $form_state['values']['op'] = variable_get('services_node_save_button_' . $node_type . '_resource_update', t('Save'));
    $form_state['node'] = $old_node;
    drupal_form_submit($node_type . '_node_form', $form_state, $old_node);

    if ($errors = form_get_errors()) {
      return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
    }
  }
  else {
    return services_error(t('Node @nid not found', array('@nid' => $old_node->nid)), 404);
  }

  $node = array('nid' => $nid);
  if ($uri = services_resource_uri(array('node', $nid))) {
    $node['uri'] = $uri;
  }
  return $node;
}
?>