2010-05-28 29 views
4

每当创建的内容项目,则显示类似这样的消息:禁用Drupal内容创建消息?

[Content Type] [Name] has been created. 

有什么办法来禁用此消息对特定用户?或者对于所有的用户也可以。

回答

3

这是node_form_submit正在创建这些消息。您可以非常轻松地在节点窗体上使用hook_form_alter,并使用您自己的node_form_submit版本。您只需复制该功能并在创建消息之前添加user_access('whatever')检查即可。

或者,您可以在preprocess_page函数中检查哪些消息正在被提供,并删除不需要的消息,但这会有点棘手。应该可以用一些正则表达式。另一方面,这种方法会更友好一些,因为你可以继续使用node_form_submit函数,并且可以在将来进行更改。

2

如果你想使用规则模块,那么你可以使用我创建的新模块"Better Rules Message"。 通过使用此设置,您可以设置一个规则,在创建节点后将删除所有消息...

希望这将在不久的将来添加到主规则模块中。

2

googletorp是对的(关于提交功能)。但不幸的是,你不能将消息与节点提交功能分开,并且复制功能(没有消息)意味着你的网站在发布安全发布时可能会中断。你必须维护你自己的那个函数版本。这可能不是一个大问题,但遵循最佳实践是一个好主意。

您需要在调用node_form_submit之前或之后编写自己的提交钩子。

在节点保存后使用提交挂钩,如果消息数组很容易处理,可以从$_SESSION['messages']中删除消息。我想这会很简单。见drupal_set_message

OR

你可以写在CSS一些类在你的身体标记和显示设置为none时状态消息的节点形式提交到页面上的返回。但是,这可能会将您的业务逻辑放在应该避免的主题层中。

4

我认为最好的做法是使用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'); 
    } 
} 
+0

我天真地认为它可以改变preprocess_page,但template_preprocess_page已经处理它。 – 2011-10-29 20:01:57

+1

至少在drupal 6中,在设置消息之前,在node_form_submit调用node_save时触发插入钩子。 – 2011-10-29 20:36:30

3

这里是我发现隐藏特定的内容类型,例如邮件的方式(节点类型是“请求”):

// 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'); 
} 
3

我写了这个功能,很方便海事组织。欢呼声

/** 
* 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 
    } 
} 

} 
3

最好的办法是将用户Disable Messages模块。 可以通过此模块禁用许多类型的消息:

  • 过滤出与完整文本字符串完全匹配的消息。
  • 过滤出与正则表达式匹配的邮件。
  • 权限专门隐藏任何角色给定类型的所有消息。
  • 禁用特定用户的所有过滤。
  • 禁用特定路径的所有过滤。
  • 仅对特定路径应用过滤。
  • 调试系统在HTML中获取消息而不显示给最终用户。