【发布时间】:2011-01-19 14:21:42
【问题描述】:
每次我使用 API 创建新论坛时,消息:
创建了新论坛等等
出现(状态消息)。
我可以压制它吗?也许有钩子?
【问题讨论】:
标签: drupal hook forum drupal-hooks
每次我使用 API 创建新论坛时,消息:
创建了新论坛等等
出现(状态消息)。
我可以压制它吗?也许有钩子?
【问题讨论】:
标签: drupal hook forum drupal-hooks
您可以使用Disable Messages 模块以非编程方式完成此操作
【讨论】:
有一个模块可以创建一个钩子,您可以使用它来更改消息。 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;
}
【讨论】:
抑制库存消息很痛苦,但可以做到。我很确定一个好方法是制作 'function template_preprocess_page(&$variables)'
在您的主题中设置它并在 $variables 上执行 print_r。我很确定即将在页面上呈现的所有消息都将在该数组中的某个位置可用,并且您可以取消设置您不想一直到页面模板的消息。
【讨论】: