Ha! The Q&A is simply built with Views, Rendered Entities, Flag, and a custom views handler. We use Flag to handle spam and Flag/Message to handle "subscriptions." The final bit of logic includes a custom views handler:
<?php
/**
* Provides a trimmed down Answer node add form for use on the Questions View.
*/
class dcorg_handler_area_answer_form extends views_handler_area {
function render($empty = FALSE) {
global $user;
if (user_access('create answer content', $user)) {
// Build an empty Answer node object for use on the form.
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => 'answer',
'language' => LANGUAGE_NONE,
);
// Wrap the node and set the node reference value to the proper Question,
// which in our case is the first argument for the View.
$node_wrapper = entity_metadata_wrapper('node', $node);
$node_wrapper->field_question = $this->view->args[0];
// Build and retrieve the node add form.
module_load_include('inc', 'node', 'node.pages');
$form = drupal_get_form('answer_node_form', $node);
return drupal_render($form);
}
else {
// Build an options string to direct links back to this page.
$options = array(
'query' => array(
'destination' => request_path(),
),
);
return '<div id="answer-node-form" class="form-item"><div class="field-name-field-answer-text"><label>'
. l(t('Login'), 'user/login', $options) . ' or ' . l(t('register'), 'user/register', $options) . ' ' . t('to answer this question.')
. '</label></div></div>';
}
}
}
?>
and a hook_form_alter():
<?php
/**
* Implements hook_form_FORM_ID_alter().
*/
function dcorg_form_answer_node_form_alter(&$form, &$form_state) {
global $user;
// Wrap the answer node for easy data access.
$answer_wrapper = entity_metadata_wrapper('node', $form['#node']);
// Set the title to reference the original question node ID.
$form['title']['#default_value'] = t('Answer to Question @nid', array('@nid' => $answer_wrapper->field_question->raw()));
// Change the value of the save button.
$form['actions']['submit']['#value'] = t('Submit');
// Simplify for everyone
$form['comment_settings']['#access'] = FALSE;
$form['field_question']['#access'] = FALSE;
$form['revision_information']['#access'] = FALSE;
$form['book']['#access'] = FALSE;
$form['author']['#weight'] = -10;
$form['options']['#weight'] = -11;
// Heavily modify for non-administrators
if (!in_array("administrator",$user->roles) && !in_array("content administrator",$user->roles)) {
// Remove title options
$form['title']['#access'] = FALSE;
// Disable the vertical tabs.
$form['additional_settings']['#access'] = FALSE;
$form['author']['#access'] = FALSE;
$form['options']['#access'] = FALSE;
}
}
?>
Comments
I am also very interested!