Drupal Message control?
Is there a module or a way to manage Drupal Message. I.e. THe message you see after creating content, e.g. "Car listing 开发者_如何学Gotitled bla has been created". I want a central point to control these messages. Most of them I do not want to display.
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.
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.
You could also try the Disable Messages module to disable specific messages from being shown to end users. Here is a quote from its project page:
Gives a site owner options to disable specific messages shown to end users. The core drupal message system as offered by drupal_set_message is an excellent way for modules to send out messages to the end users. However not all drupal site owners are keen to show all the messages sent out by drupal core and all modules to their users. This module gives site administrators a reasonably powerful way to filter out messages shown to the end users.
Some of its features are:
- Filter out messages that match a full text string exactly.
- Filter out messages that match a regular expression.
- Permissions to specifically hide all messages of a given type from any role.
- Disable all filtering for specific users.
- Disable all filtering for specific paths.
- Apply filtering only for specific paths.
- Debug system to get messages in the HTML without showing it to the end users.
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.
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.
精彩评论