发表评论时如何覆盖drupal默认消息?

发布于 2024-11-17 11:59:54 字数 334 浏览 2 评论 0原文

我想覆盖发布评论的默认消息。

例如,我想显示“您的评论已发送给网站管理员,并将保持私密。”而不是“您的评论已排队等待网站管理员审核,并将被保留”批准后发布。

我尝试了挂钩插入,但它没有覆盖该消息:

function custom_comment_insert($comment) {
    //drupal_get_messages(null, true);
    unset($_SESSION['messages']);
    drupal_set_message(t('override like this.'));
}

I would like to overwrite a default message for posting a comment.

For example, I would like to display "Your comment has been sent to the site moderator and will remain private." instead of "Your comment has been queued for review by site administrators and will be published after approval."

I tried hook insert, but it didn't override the message:

function custom_comment_insert($comment) {
    //drupal_get_messages(null, true);
    unset($_SESSION['messages']);
    drupal_set_message(t('override like this.'));
}

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

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

发布评论

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

评论(4

听你说爱我 2024-11-24 11:59:54

不要使用它,而是使用字符串覆盖来更改消息。一般来说,如果你想重写文本,不要修改它,而是覆盖它。

在 Drupal 7 中,您可以使用 settings.php 直接更改它:(参见 http://preprocess.me/drupal-override-strings-in-settingsphp)

$conf['locale_custom_strings_en']['Your comment has been queued for review by site administrators and will be published after approval.'] = 'Your comment has been sent to the site moderator and will remain private.';

Don't use that, use String Overrides to change the message instead. In general, if you want to reword text, don't hack it, override it.

In Drupal 7, you can use settings.php to change it directly: (See http://preprocess.me/drupal-override-strings-in-settingsphp)

$conf['locale_custom_strings_en']['Your comment has been queued for review by site administrators and will be published after approval.'] = 'Your comment has been sent to the site moderator and will remain private.';
£烟消云散 2024-11-24 11:59:54

@Maciej Zgadzaj 你的解决方案也工作得很好。
我在 hook_form_alter http://bit.ly/12u09O 上找到了一个有用的教程

function private_comments_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
        case 'comment_node_proposed_rules_form':
            unset($form['field_comment_public']);
        $form['#submit'][] = 'private_comments_comments_form_submit';
        //$form['#submit'][]='my_submit_test';
        break;
}
}
function private_comments_comments_form_submit($form, &$form_state){
unset($_SESSION['messages']);
drupal_set_message("this is a form test");
}

@Maciej Zgadzaj Your solution works fine as well.
I found a useful tutorial on hook_form_alter http://bit.ly/12u09O

function private_comments_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
        case 'comment_node_proposed_rules_form':
            unset($form['field_comment_public']);
        $form['#submit'][] = 'private_comments_comments_form_submit';
        //$form['#submit'][]='my_submit_test';
        break;
}
}
function private_comments_comments_form_submit($form, &$form_state){
unset($_SESSION['messages']);
drupal_set_message("this is a form test");
}
能否归途做我良人 2024-11-24 11:59:54

保存新评论后,该消息将添加到 comment_form_submit() 中的会话中。

因此,要么更改评论表单,在主表单之后添加自己的提交功能,然后删除那里的消息(这似乎是一个更好的主意,因为这样只有在真正发布新评论时才会执行此操作),或...

实际上,没有“或”。最初想建议像 hook_init() 这样的东西作为替代方案,但是不,你不想把它放在那里。 ;)

The message is being added to session in comment_form_submit(), AFTER new comment is saved.

So either you alter comment form, add your own submit function after the main one, and remove the message there (which seems to be a better idea, as this way this is going to be done only when a new comment is really posted), or...

Actually, no 'or'. Originally wanted to suggest something like hook_init() as an alternative, but no, you don't want to put it there. ;)

旧人 2024-11-24 11:59:54

Drupal Answers SE 其中给出的解决方案是使用 array_search() 搜索实际的消息数组,然后比较翻译后的字符串以识别要更改的字符串的键。然后展示如何更改它。

当作为模块的一部分实现时,该解决方案有效,而更改设置文件中的消息字符串则无效。

There is question over at Drupal Answers SE where the solution given is to use array_search() to search the actual message array, and then compare the translated strings to identify the key of the string to alter. Then showing how to alter it.

This solution works when implemented as part of a module, while changing the message string in the setting file does not.

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