function _comment_resource_create in Services 6.3
Same name and namespace in other branches
- 7.3 resources/comment_resource.inc \_comment_resource_create()
Adds a new comment to a node and returns the cid.
Parameters
$comment: An object as would be returned from comment_load().
Return value
Unique identifier for the comment (cid) or errors if there was a problem.
1 string reference to '_comment_resource_create'
- _comment_resource_definition in resources/
comment_resource.inc - @file Will define the comments resource for dealing with node comments
File
- resources/
comment_resource.inc, line 232 - Will define the comments resource for dealing with node comments
Code
function _comment_resource_create($comment) {
// Adds backwards compatability with regression fixed in #1083242
$comment = _services_arg_value($comment, 'comment');
if (empty($comment['nid'])) {
return services_error(t('A nid must be provided'));
}
// Setup form_state
$form_state = array();
$form_state['values'] = $comment;
$form_state['values']['op'] = variable_get('services_comment_save_button_resource_create', t('Save'));
$comment_empty = array(
'nid' => $comment['nid'],
'cid' => NULL,
);
if (!empty($comment['pid'])) {
$comment_empty['pid'] = $comment['pid'];
}
$ret = drupal_execute('comment_form', $form_state, $comment_empty);
if ($errors = form_get_errors()) {
return services_error(implode(" ", $errors), 406, array(
'form_errors' => $errors,
));
}
// Load latest created comment.
$recent_comments = comment_get_recent(1);
$cid = $recent_comments[0]->cid;
return array(
'cid' => $cid,
'uri' => services_resource_uri(array(
'comment',
$cid,
)),
);
}