隐藏“已创建新论坛 XXX” Drupal 中的消息

发布于 2024-10-12 23:12:18 字数 122 浏览 4 评论 0原文

每次我使用 API 创建新论坛时,都会出现以下消息:

创建了新论坛等等

出现(状态消息)。

我可以压制它吗?也许有一个钩子?

Every time I create a new forum using the API, the message:

Created new forum blah blah

appears (status message).

Can I suppress it? maybe with a hook?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

骑趴 2024-10-19 23:12:18

您可以使用禁用消息模块以非编程方式执行此操作

You could do this non-programmatically by using the Disable Messages module

听不够的曲调 2024-10-19 23:12:18

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

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;
}                
月竹挽风 2024-10-19 23:12:18

压制股票消息是一件痛苦的事情,但这是可以做到的。我很确定一个好方法是

在您的主题中设置“function template_preprocess_page(&$variables)”并在 $variables 上执行 print_r 。我非常确定即将在页面上呈现的所有消息都将在该数组中的某个位置可用,您只需取消设置那些您不想将其一直添加到页面模板的消息即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文