Pre-fill comment subject line

I often find it handy to make a small module for most of my Drupal project the purpose of which is to perform little tweaks on default Drupal core or other module behavior. Usually this small utility module lives in /sites/all/modules/custom/tweaks/tweaks.module or something to that effect.

Having such a module around is a quick way to tap into the power of Drupal hooks.  For example, a client requested that the subject lines of any comments be pre-filled with the node name, prefixed with "Re:".  This was easily accomplished with a quick hook_form_alter, like so:


function tweaks_form_alter($&form, $form_state, $form_id) {
if($form_id == 'comment_form') {
$node = node_load($form['nid']['#value']);
$form['subject']['#default_value'] = "Re: . $node->title;
}
}

Easy.