function commons_answers_add_answer_form_submit in Drupal Commons 6.2
File
- modules/
features/ commons_answers/ commons_answers.module, line 239
Code
function commons_answers_add_answer_form_submit($form, &$form_state) {
global $user;
$account = $user;
$question_nid = $form_state['values']['question_nid'];
$question_node = node_load($question_nid);
$answer = $form_state['values']['answer'];
$node = new stdClass();
// Provide a human-readable title for listings where the title
// may be displayed, such as admin/content/node or a listing of answers.
$node->title = substr($answer, 0, 30);
if (strlen($answer) > 30) {
$node->title .= '...';
}
$node->body = $answer;
$node->type = 'answer';
$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;
$node->field_answer_question[0]['nid'] = $question_nid;
if (!empty($question_node->og_groups)) {
$node->og_groups = $question_node->og_groups;
$node->og_public = $question_node->og_public;
}
node_save($node);
if (!empty($node->nid)) {
$form_state['redirect'] = array(
'node/' . $question_nid,
'',
'node-' . $node->nid,
);
}
}