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.'));
}
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.';
@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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With