Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to overwrite drupal default message when posting comments?

I would like to overwrite a default message for posting a comment.

For example, I would like to display "Your comment has been sent to the site moderator and will remain private." instead of "Your comment has been queued for review by site administrators and will be published after approval."

I tried hook insert, but it didn't override the message:

function custom_comment_insert($comment) {
    //drupal_get_messages(null, true);
    unset($_SESSION['messages']);
    drupal_set_message(t('override like this.'));
}
like image 782
Vlad Vinnikov Avatar asked Feb 24 '23 17:02

Vlad Vinnikov


2 Answers

Don't use that, use String Overrides to change the message instead. In general, if you want to reword text, don't hack it, override it.

In Drupal 7, you can use settings.php to change it directly: (See http://preprocess.me/drupal-override-strings-in-settingsphp)

$conf['locale_custom_strings_en']['Your comment has been queued for review by site administrators and will be published after approval.'] = 'Your comment has been sent to the site moderator and will remain private.';
like image 131
Sacha Chua Avatar answered Feb 26 '23 06:02

Sacha Chua


@Maciej Zgadzaj Your solution works fine as well. I found a useful tutorial on hook_form_alter http://bit.ly/12u09O

function private_comments_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
        case 'comment_node_proposed_rules_form':
            unset($form['field_comment_public']);
        $form['#submit'][] = 'private_comments_comments_form_submit';
        //$form['#submit'][]='my_submit_test';
        break;
}
}
function private_comments_comments_form_submit($form, &$form_state){
unset($_SESSION['messages']);
drupal_set_message("this is a form test");
}
like image 43
Vlad Vinnikov Avatar answered Feb 26 '23 07:02

Vlad Vinnikov