2011-01-19 9 views
1

に、私はAPIを使用して新しいフォーラムを作成するたびに、「作成した新しいフォーラムXXX」のメッセージを非表示に、メッセージ:Drupalの

作成された新しいフォーラム何とか何とか

表示されます(ステータスメッセージ) 。

私はそれを抑制できますか?多分フックで?

答えて

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(& $変数)'を作ることだと確信しています。

あなたのテーマにそれらを設定し、$変数でprint_rを行います。ページ上でレンダリングしようとしているすべてのメッセージは、その配列のどこかで利用可能になります。ページテンプレートを作成したくないメッセージの設定を解除するだけで済みます。

1

あなたはDisable Messagesモジュール

を使用して、この非プログラムで行うことができます