每當創建的內容項目,則顯示類似這樣的消息:禁用Drupal內容創建消息?
[Content Type] [Name] has been created.
有什麼辦法來禁用此消息對特定用戶?或者對於所有的用戶也可以。
每當創建的內容項目,則顯示類似這樣的消息:禁用Drupal內容創建消息?
[Content Type] [Name] has been created.
有什麼辦法來禁用此消息對特定用戶?或者對於所有的用戶也可以。
這是node_form_submit
正在創建這些消息。您可以非常輕鬆地在節點窗體上使用hook_form_alter,並使用您自己的node_form_submit
版本。您只需複製該功能並在創建消息之前添加user_access('whatever')
檢查即可。
或者,您可以在preprocess_page函數中檢查哪些消息正在被提供,並刪除不需要的消息,但這會有點棘手。應該可以用一些正則表達式。另一方面,這種方法會更友好一些,因爲你可以繼續使用node_form_submit
函數,並且可以在將來進行更改。
如果你想使用規則模塊,那麼你可以使用我創建的新模塊"Better Rules Message"。 通過使用此設置,您可以設置一個規則,在創建節點後將刪除所有消息...
希望這將在不久的將來添加到主規則模塊中。
googletorp是對的(關於提交功能)。但不幸的是,你不能將消息與節點提交功能分開,並且複製功能(沒有消息)意味着你的網站在發佈安全發佈時可能會中斷。你必須維護你自己的那個函數版本。這可能不是一個大問題,但遵循最佳實踐是一個好主意。
您需要在調用node_form_submit之前或之後編寫自己的提交鉤子。
在節點保存後使用提交掛鉤,如果消息數組很容易處理,可以從$_SESSION['messages']
中刪除消息。我想這會很簡單。見drupal_set_message
OR
你可以寫在CSS一些類在你的身體標記和顯示設置爲none時狀態消息的節點形式提交到頁面上的返回。但是,這可能會將您的業務邏輯放在應該避免的主題層中。
你可以嘗試使用下面的模塊在Drupal來禁用特定的消息 - http://drupal.org/project/disable_messages
我認爲最好的做法是使用hook_nodeapi()
和drupal_get_messages('status')
。 $op
對於hook_nodeapi()
將是insert
。例如:
mymodule_nodeapi(&$node, $op) {
if ($node->type == 'content_type_to_check_for' && $op == 'insert') {
drupal_get_messages('status');
}
}
您可以在drupal中使用stringoverrides模塊! :)
這裏是我發現隱藏特定的內容類型,例如郵件的方式(節點類型是「請求」):
// specific node type form alteration hook (implements [hook_form_FORM_ID_alter][1]())
function MYCUSTOMMODULE_form_request_node_form_alter(&$form, &$form_state) {
// ...
// custom validation function
$form['#validate'][] = '_custom_request_node_form_validate';
// ...
}
function _custom_request_node_form_validate($form, &$form_state) {
//...
// here we can set a submit handler that is executed before
// node_form_submit which sets the messages we are trying to hide
$form_state['submit_handlers'][] = '_custom_request_node_disable_msg';
//...
}
function _custom_request_node_disable_msg($form, &$form_state) {
//...
// clear status messages
drupal_get_messages('status');
}
我寫了這個功能,很方便海事組織。歡呼聲
/**
* method to assure only wanted messages are shown, filtered by optional type
*/
function my_module_filter_messages() {
// before emptying the messages cache to get rid of i.e. status messages (uncommented so not kept), first save the types you want to keep in arrays
// this way you can exactly determine which will be displayed. Use free types such as "admin" or "custom" for own messages
// could be made smarter with params for node types or message types or with a variable_get (to turn on/off all messages of some sort (i.e. admin))
// $statuses = drupal_get_messages('status'); // suppressed by commenting
$errors = drupal_get_messages('error');
$warnings = drupal_get_messages('warning');
$customs = drupal_get_messages('custom');
$admins = drupal_get_messages('admin');
unset($_SESSION['messages']);
// dpm($admin);
global $user;
foreach ($statuses['status'] as $status) {
drupal_set_message($status, 'status'); // standard type
}
foreach ($errors['error'] as $error) {
drupal_set_message($error, 'error'); // standard type
}
foreach ($warnings['warning'] as $warning) {
drupal_set_message($warning, 'warning'); // standard type
}
foreach ($customs['custom'] as $custom) {
drupal_set_message($custom, 'custom'); // selfcreated type, note you might want to css this like the others
}
// only for admin's eyes, handy for testing
if($user->uid==1){
foreach ($admins['admin'] as $admin) {
drupal_set_message($admin, 'admin'); // selfcreated type, note you might want to css this like the others
}
}
}
最好的辦法是將用戶Disable Messages模塊。 可以通過此模塊禁用許多類型的消息:
我天真地認爲它可以改變preprocess_page,但template_preprocess_page已經處理它。 – 2011-10-29 20:01:57
至少在drupal 6中,在設置消息之前,在node_form_submit調用node_save時觸發插入鉤子。 – 2011-10-29 20:36:30