function _node_resource_create in Services 6.2
Same name and namespace in other branches
- 6.3 resources/node_resource.inc \_node_resource_create()
- 7.3 resources/node_resource.inc \_node_resource_create()
- 7 services/node_service/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 30 - CRUD resource functionality for nodes.
Code
function _node_resource_create($node) {
$node = (object) $node;
if (!isset($node->name)) {
//assign username to the node from $user created at auth step.
global $user;
$node->name = $user->name;
}
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,
)),
);
}