_node_resource_create

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

Creates 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

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

Return value

An associative array contained the new node's nid and, if applicable, the fully qualified URI to this resource.

See also

drupal_execute()

Code

resources/node_resource.inc, line 229

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

  if (!isset($node['name'])) {
    // Assign username to the node from $user created at auth step.
    global $user;
    $node['name'] = $user->name;
  }

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

  // 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_create', t('Save'));

  drupal_form_submit($node_type . '_node_form', $form_state, (object) $node);

  if ($errors = form_get_errors()) {
    return services_error(implode(" ", $errors), 406, array('form_errors' => $errors));
  }
  // Fetch $nid out of $form_state
  $nid = $form_state['nid'];
  // Only add the URI for servers that support it.
  $node = array('nid' => $nid);
  if ($uri = services_resource_uri(array('node', $nid))) {
    $node['uri'] = $uri;
  }
  return $node;
}
?>