You are here

function _node_resource_create in Services 7

Same name and namespace in other branches
  1. 6.3 resources/node_resource.inc \_node_resource_create()
  2. 6.2 services/node_service/node_resource.inc \_node_resource_create()
  3. 7.3 resources/node_resource.inc \_node_resource_create()
1 string reference to '_node_resource_create'
node_resource_service_resource in services/node_service/node_resource.module

File

services/node_service/node_resource.inc, line 9

Code

function _node_resource_create($node) {
  $node = (object) $node;
  if (!isset($node->type)) {
    return services_error('Missing node type', 406);
  }

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

  // Setup form_state
  $values = (array) $node;
  $form_state = array();
  $form_state['values'] = $values;
  $form_state['values']['op'] = t('Save');
  $ret = drupal_execute($node->type . '_node_form', $form_state, $node);

  // Fetch $nid out of $form_state
  $nid = $form_state['nid'];
  if ($errors = form_get_errors()) {
    return services_error(implode("\n", $errors), 406);
  }
  return (object) array(
    'nid' => $nid,
    'uri' => services_resource_uri(array(
      'node',
      $nid,
    )),
  );
}