老葛的Drupal培训班 Think in Drupal
你使用creativejuice_filter_tips()来向终端用户显示帮助文本。在默认情况下,显示一个短消息,其中带有一个指向http://example.com/?q=filter/tips的链接,而链接页面则包含了所有过滤器的详细说明。
/**
* Implementation of hook_filter_tips().
*/
function creativejuice_filter_tips($delta, $format, $long = FALSE) {
return t('Insert a random sentence into your post with the [juice!] tag.');
}
在前面的代码中,无论是简洁的帮助文本还是详细的帮助文本,都使用了相同的文本,如果你想返回一个更详细的文本解释时,你可以检查$long参数,如下所示:
/**
* Implementation of hook_filter_tips().
*/
function creativejuice_filter_tips($delta, $format, $long = FALSE) {
if ($long) {
// Detailed explanation for http://example.com/?q=filter/tips page.
return t('The Creative Juice filter is for those times when your
brain is incapable of being creative. These times come for everyone,
when even strong coffee and a barrel of jelly beans do not
create the desired effect. When that happens, you can simply enter
the [juice!] tag into your posts...'
);
}
else {
// Short explanation for underneath a post's textarea.
return t('Insert a random sentence into your post with the [juice!] tag.');
}
}
一旦在模块列表页面启用了这个模块,那么就可以使用creativejuice过滤器了,你可以将它应用在一个已有的输入格式中,也可以应用在一个新建的输入格式中。例如,将creativejuice过滤器添加到Filtered HTML输入格式中以后,节点编辑表单中的“输入格式”部分,将如图11-8所示。

图 11-8. Filtered HTML输入格式现在包含了creativejuice过滤器,前面的节点编辑表单中的“输入格式”部分给出了相应指示。
你可以使用合适的输入格式创建一个日志条目,然后提交包含[juice!]标签的文本:
Today was a crazy day. [juice!] Even if that sounds a little odd,
it still doesn't beat what I heard on the radio. [juice!]
提交的内容将被转换为如下所示的内容:
Today was a crazy day! Generally speaking, life flowed in its accustomed stream
through the red tape of officialdom. Even if that sounds a little odd, it still
doesn't beat what I heard on the radio. Barren in intellect, she reverted to another
matter like a damp-handed auctioneer.