禁用Drupal内容创建消息?

时间:2010-05-28 10:10:44

标签: drupal

每当创建内容项时,都会显示如下消息:

[Content Type] [Name] has been created.

有没有办法为特定用户禁用此消息?或者对所有用户也没关系。

9 个答案:

答案 0 :(得分:4)

我认为最佳做法是使用hook_nodeapi()drupal_get_messages('status')$op的{​​{1}}为hook_nodeapi()。例如:

insert

答案 1 :(得分:3)

创建这些消息的是node_form_submit。您可以非常轻松地在节点表单上使用hook_form_alter,并使用您自己的node_form_submit版本。您需要做的就是复制该函数并在创建该消息之前添加user_access('whatever')检查。

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

答案 2 :(得分: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 :(得分:3)

我写了这个函数,非常方便的imo。干杯

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

}

答案 4 :(得分:3)

最好的方法是用户Disable Messages模块。 此模块可以禁用多种消息:

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

答案 5 :(得分:2)

如果要使用“规则”模块,则可以使用我创建的名为"Better Rules Message"的新模块。 通过使用此功能,您可以设置一个规则,该规则将在创建节点后删除所有消息...

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

答案 6 :(得分:2)

googletorp是对的(关于提交功能)。但遗憾的是,您无法将消息与节点提交功能分离,并且重复功能(没有消息)将意味着您的站点在发布安全发布时可能会中断。您必须维护自己的该功能版本。这可能不是什么大问题,但遵循最佳实践是个好​​主意。

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

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

OR

您可以在body标签中的CSS中编写一些类,并在节点表单提交的页面上返回状态消息时将显示设置为none。但这可能会将您的业务逻辑放在您应该避免的主题层中。

答案 7 :(得分:2)

您可以在drupal中使用stringoverrides模块! :)

答案 8 :(得分:1)

您可以尝试使用以下模块禁用Drupal中的特定邮件 - http://drupal.org/project/disable_messages

相关问题