Every time I create a ne开发者_JAVA技巧w forum using the API, the message:
Created new forum blah blah
appears (status message).
Can I suppress it? maybe with a hook?
You could do this non-programmatically by using the Disable Messages module
There is a module that creates a hook that you can use to alter messages. http://drupal.org/project/messages_alter
I think that it would work for your use case, however if you need something it doesn't offer or just want to roll your own option: A quick look at the module will give you ideas on how you can create your own implementation if you need it.
I honestly can't remember why we did it ourselves, instead of using the module, but here is some really simple example code.
/**
* function to check the messages for certian things and alter or remove thme.
* @param $messages - array containing the messages.
*/
function itrader_check_messages(&$messages){
global $user;
foreach($messages as &$display){
foreach($display as $key => &$message){
// this is where you'd put any logic for messages.
if ($message == 'A validation e-mail has been sent to your e-mail address. In order to gain full access to the site, you will need to follow the instructions in that message.'){
unset($display[$key]);
}
if (stristr($message, 'processed in about')){
unset($display[$key]);
}
}
}
// we are unsetting any messages that have had all their members removed.
// also we are making sure that the messages are indexed starting from 0
foreach($messages as $key => &$display){
$display = array_values($display);
if (count($display) == 0){
unset($messages[$key]);
}
}
return $messages;
}
Theme Function:
/**
* Theme function to intercept messages and replace some with our own.
*/
function mytheme_status_messages($display = NULL) {
$output = '';
$all_messages = drupal_get_messages($display);
itrader_check_messages($all_messages);
foreach ($all_messages as $type => $messages) {
$output .= "<div class=\"messages $type\">\n";
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>'. $message ."</li>\n";
}
$output .= " </ul>\n";
}
else {
$output .= $messages[0];
}
$output .= "</div>\n";
}
return $output;
}
It is a pain to suppress the stock messages but it can be done. I'm pretty sure a good way is to make 'function template_preprocess_page(&$variables)'
Set that up in your theme and do a print_r on $variables. I'm pretty sure all the messages that are about to be rendered on the page will be available somewhere in that array and you can just unset the ones you don't want to make it all the way to the page template.
精彩评论