You are here

function commons_answers_add_question_form_submit in Drupal Commons 6.2

File

modules/features/commons_answers/commons_answers.module, line 183

Code

function commons_answers_add_question_form_submit($form, &$form_state) {
  global $user;
  $account = $user;
  $node = new stdClass();
  if (!empty($form_state['values']['group_nid'])) {
    $group_nid = $form_state['values']['group_nid'];
    $group = node_load($group_nid);

    // Set the question to be private if the group is private.
    // This will automatically propogate to answers submitted
    // to this question.
    $node->og_public = !$group->og_private;
  }
  $title = $form_state['values']['title'];
  $question = $form_state['values']['body'];
  $node->title = $title;
  $node->body = $question;
  $node->type = 'question';
  $node->created = $SERVER['REQUEST_TIME'];
  $node->promote = 0;
  $node->sticky = 0;

  // Filtered HTML should be format 1 in Commons.
  $formats = filter_formats();
  if (!empty($formats)) {
    $format = array_shift($formats);
    $node->format = $format->format;
  }
  $node->status = 1;
  $node->uid = $account->uid;

  // By default, the questin
  $node->og_groups = array(
    $group_nid,
  );
  node_save($node);
  drupal_set_message(t('The question has been created.'));
}