每次我使用 API 创建新论坛时,消息:
创建了新的论坛等等
出现(状态信息)。
我可以压制它吗?也许用钩子?
您可以使用禁用消息模块以非编程方式执行此操作
抑制库存消息是一种痛苦,但可以做到。我很确定一个好方法是制作'function template_preprocess_page(&$variables)'
在您的主题中设置它并在 $variables 上执行 print_r。我很确定即将在页面上呈现的所有消息都将在该数组中的某个位置可用,并且您可以取消设置您不想一直到页面模板的消息。
有一个模块可以创建一个钩子,您可以使用它来更改消息。http://drupal.org/project/messages_alter
我认为它适用于您的用例,但是如果您需要它不提供的东西或者只是想推出自己的选择:快速浏览该模块将为您提供有关如何创建自己的实现的想法,如果您需要它。
老实说,我不记得为什么我们自己做,而不是使用模块,但这里有一些非常简单的示例代码。
/**
* 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 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;
}