For those who have the time to study this code - both of you - check this out.

I wanted to use the nodereview module but I needed to make a few extensions and alterations to the functionality.

Without changing a line of code in the nodereview.module, I can get it to:
1) use the node->body to store info (in this case a description of the reviewer). I used the content types admin function to change the description of the body field, but I think i could have done it in hook_node_info
2) stop nodereview from allowing an admin to enable reviews of reviews (illogical and might loop?), and stop reviews of the new node type I introduced: axis
3) use a new data type of axis in an external table instead of defining them for each node type, so replace the selection list created by nodereview with a new one taken dfropm the external table

There is more code inthe nodereview2h module than just hook_form_alter, but you can see from this function just how much I have been able to override in nodereview! Stunning. Drupal Rocks!

function nodereview2h_form_alter($form_id, &$form) {
  if ($form_id == 'nodereview_node_form') {
    $node_info = node_get_types('type', 'nodereview');
    $form['body'] = array(
      '#type' => 'textarea',
      '#title' => t($node_info->body_label),
      '#default_value' => $form['#node']->body,
      '#required' => TRUE,
      '#weight' => -10
    );
  }
  if ($form_id == 'nodereview_configure') {
    $form['nodereview']['types']['axis'] = array();
    $form['nodereview']['types']['nodereview'] = array();
  }
  if ($form_id == 'nodereview_configure_axes') {
    $temp = array(
      '#type' => 'fieldset',
      '#title' => t('review axes'),
      '#collapsible' => TRUE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
    );
    //using nodereview_axes.weight to store the nid of the related axis record
    //can't use aid=nid because aid is autoincremented
    $result = db_query("SELECT r.aid, n.title as tag, n.type , a.nid as weight
                        FROM {axis} a 
                        INNER JOIN {node} n
                          ON n.nid = a.nid
                        LEFT JOIN {nodereview_axes} r
                          ON a.nid = r.weight
                          AND r.node_type = '%s'
                        ORDER BY a.rating
                        ", $form['use']['node_type']['#value']);
    $axes = array();
    while ($record = db_fetch_object($result)) {
        $row = _nodereview_configure_axis($record);
        $row['use']['#default_value'] = ($record->aid > 0 );
        $row['weight']['#type'] = 'hidden';
        $row['weight']['#value'] = $row['weight']['#default_value'];
        $axes[] = $row;
    }  
    $temp += $axes;
    $form['axes'] = $temp;
  }
}

Comments

twohills’s picture

BTW, I've ironed a few bugs out of the code above so please don't use it verbatim. it is the PRINCIPLE of the thing I'm passing on here...

vm’s picture

consider correcting it and adding it as a handbook page for others to use as time goes on and the fourm pushes your post to the basement.