Tags/topics: 
2
Answers
Vote up!
6
Vote down!

What Module is providing this Q&A ?

Totally unrelated but... The Q&A here looks awesome.
Any ideas what module is being used or if its not a module perhaps a link to some instructions maybe?
Thanks in advance

Asked by: Mario Baron
on July 7, 2013

Comments

2 Answers

Vote up!
1
Vote down!

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;
  }
}
?>
Josh Miller
Answer by: Josh Miller
Posted: Apr 25, 2014
Vote up!
0
Vote down!

Hi Josh,

Can you provide details, how did you created this Awesome Q&A system. Did you achieve by Views only or along with code whatever you have mentioned above, if both can you describe the procedure. Very very thanks.

Answer by: CodeNext
Posted: May 7, 2016