Is there a module or a way to manage Drupal Message. I.e. THe message you see after creating content, e.g. "Car listing titled bla has been created". I want a central point to control these messages. Most of them I do not want to display.
Hi,
Most Drupal modules use drupal_set_message function located on includes/bootstrap.inc inside your drupal installation's main folder. Just change it there and you are done ;)
Hope it helps, PS: May be you would like to change the standard form error handling function as well
If you have created an error message and you immediately know you don't want to display it, you can remove it from the Drupal error array as follows:
array_pop($_SESSION['messages']['error']);
That will remove the most recently created error message, but will leave the form in error state. It's a bit of a hacky way to do it, but it saves you having to dive into coding the Drupal core.
You can also hunt for specific entries in the array and unset them, but that's a bit more work.
I don't think you can manage messages like that. You wont know which module posted the message or why, all you will get is the message and it's type, warning, error etc.
If you want to alter messages you can do it in preprocess_page
, where you have the messages available, or you can do it before, by modifying the global $_SESSION
variable where the messages are stored.
But like I said, there isn't a good way to filter messages, so you will have a very hard time if you want to remove message X from module Y. If you really want to, you can use RegEx, but it will quickly become unmanageable.
I was preparing a blog post about it, but I can tell you some hints already:
- Use String Overrides module to replace the message (via UI). If you want to hide it, then leave it blank. These replacements are stored in global variables, (not need to access database, so there is no performance penalty), but because the same reason is not recommended to use it for hundreds of strings, only few of them.
- Use http://www.michaelbarton.name/2010/07/09/drupal-module-status-messages-alter/ This module is very new but looks promising. This can be a more powerful solution for developers, because lets you to include variables in the string, regex, etc.
Hope it helps, I will leave a comment here when I write the article during this week.
You can remove
print $messages
fromm page.tpl.php of your theme if you don't want them to display at all.
However, generally it's better for usability to have feedback to users' actions.