Change a comment's body programatically I am building a small custom module that will change the value of a comment's body when the comment in posted. So far I have:

function comment_loader_comment_insert($comment) {
}


So pretty much nothing, just that I want to use hook_comment_insert to change after the comment has been posted.

So what do I need to affect the comment body?

[I am a student who is just learning php and drupal, so clarity is appreciated]

edit:

code so far:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function comment_loader_form_comment_form_alter(&amp;$form, &amp;$form_state, &amp;$form_id) {
  $form['#validate'][] = 'comment_loader_comment_form_validate';
}

/**
 * Implements hook_form_validate().
 */
function comment_loader_comment_form_validate($form, &amp;$form_state) {
  $new_body = 'some text';
  $form_state['values']['comment_body']['#object']-&gt;comment_body['und'[0]['value'] = $new_body;
}


Still doesn't have any affect. I am no working in a development environment so I don't know if there are errors.
hook_comment_insert() is fired after the comment body has already been saved to the database, so it's probably not the hook you're looking for.

Instead you could hook up your own validation function to the comment form and alter the body there. That way you're not having to make any extra db calls.

In it's simplest terms you would implement hook_form_FORM_ID_alter() and add the validation function like so:

function MYMODULE_form_comment_form_alter(&amp;$form, &amp;$form_state, &amp;$form_id) {
  $form['#validate'][] = 'MYMODULE_comment_form_validate';
}

function MYMODULE_comment_form_validate($form, &amp;$form_state) {
  $current_body = $form_state['values']['comment_body'][LANGUAGE_NONE][0]['value'];

  $new_body = $current_body . ' some extra text';

  $form_state['values']['comment_body'][LANGUAGE_NONE][0]['value'] = $new_body;
}