I want to change or hide a message shown from the CommentForm
class.
In my entity_insert()
hook I either unset $_SESSION['messages']
and add a new message or call drupal_get_message($type, TRUE)
.
The problem is that the new message will be set before the one I want to change; if I unset the message array, the new message will be gone too.
I also tried to hook in the specific form and add a submission handler, but that doesn't work.
/**
* Implements hook_form_FORM_ID_alter().
*/
function my_module_form_comment_form_alter(&$form, FormStateInterface $form_state) {
$form['actions']['submit']['#submit'][] = 'my_module_comment_form_submit';
}
/**
* Submit handler.
*/
function my_module_comment_form_submit(&$form, FormStateInterface $form_state) {
$message = $_SESSION['messages'];
}
How can I programmatically change a system message?