2011-01-19 28 views

回答

0

有一个模块可以创建一个可以用来更改消息的钩子。 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; 
}     
0

抑制股票消息是一种痛苦,但它可以完成。我很确定一个好方法是使'function template_preprocess_page(& $ variables)'

在你的主题中设置它,并在$变量上执行print_r。我非常肯定,即将在页面上呈现的所有消息都将在该数组中的某个位置可用,并且您可以取消那些不想让它一直到页面模板的消息。