You are here

function _comment_resource_create in Services 7.3

Same name and namespace in other branches
  1. 6.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

resources/comment_resource.inc, line 201

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'));
  }
  $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 a pid is provide use it
  if (!empty($comment['pid'])) {
    $comment_empty['pid'] = $comment['pid'];
  }
  $comment_empty = (object) $comment_empty;
  $form_state['programmed_bypass_access_check'] = FALSE;
  $ret = drupal_form_submit('comment_form', $form_state, $comment_empty);

  // Error if needed.
  if ($errors = form_get_errors()) {
    return services_error(implode(" ", $errors), 406, array(
      'form_errors' => $errors,
    ));
  }
  $comment = $form_state['comment'];
  return array(
    'cid' => $comment->cid,
    'uri' => services_resource_uri(array(
      'comment',
      $comment->cid,
    )),
  );
}