Drupal China
主要内容描述:让Drupal知道你模块的存在
Drupal"钩子“描述:hook_help
在Drupal 5.x里,hook_help将不在提供关于你模块的基本信息,名字和描述文字。所有模块现在需要一个名叫modulename.info的文件来包含所有关于该模块的信息。例如,在我们这个例子里,"onthisdate.info'。
一般格式是:
; $Id$
name = Module Name
description = A description of what your module does.没有该文件,你的模块在不会在模块列表里出现!
在我们的例子里,可以包含下列内容:
; $Id$
name = On this date
description = A block module that lists links to content such as blog entries or forum discussions that were created one week ago.在保存到你的模块文件夹sites/all/modules/onthisdate之前,把上面代码加入到一个名叫onthisdate.info文件里。
另外也可以选择加入(不是必须)下面两行代码:
dependencies = module1 module2 module3
package = "Your arbitrary grouping string"这两行代码在我们这个例子模块里没有作用,我们将不需要写入。如果你的模块需要其他模块的支持,只有在其他所有必须的模块都激活之后,Drupal才允许激活你的模块。
如果你把你的模块指派到一个包(package)里,在admin/build/modules页面里将会把所有在一个包里的模块放到同一个类别里。如果你不指派,它讲被列为无分类。不指派你的模块是完全可以的。一般来说,包是用在一起发放的模块或者需要用在一起的模块身上。如果任何怀疑的地方,可以在这一点上什么都不写。
一些已经存在得包区的例子:
这些文件使用ini格式并且包含; $Id$来使CVS插入文件ID信息。
请看PHP.net parse_ini_file documentation来获得更多ini文件信息。
我们还可以提供更多我们模块的帮助的附加信息。因为上述.info文件的使用,这个钩子(hook_help)现在是随意的(不是必须的hook)。但是实现它仍是不错的做法。这个函数的钩子名字叫'help',所以先来实现这个onthisdate_help函数。
<?php
function onthisdate_help($section='') {
}
?>$section是一个在Drupal或者模块帮助里提供帮助文字的变量。建议使用switch语句来处理这个变量。你将在其他模块里看到这种写代码的格式。
<?php
/**
* Display help and module information
* @param section which section of the site we're displaying help
* @return help text for section
*/
function onthisdate_help($section='') {
$output = '';
switch ($section) {
case "admin/help#onthisdate":
$output = '<p>'. t("Displays links to nodes created on this date"). '</p>';
break;
}
return $output;
} // function onthisdate_help
?>admin/help#modulename的情况是Drupal核在主要帮助页面(/admin/help or ?q=admin/help)添加一个连接。 你最终应该多加一些文字来为用户提供更好的帮助信息。
关于帮助钩的更多信息:
Drupal HEAD
把上面代码写到一个名叫onthisdate.module的文件,然后保存到你的Drupal安装目录里。
原文:http://drupal.org/node/82936
最新评论
2010-03-16 12:16:55
2010-03-16 12:16:17
2010-03-16 12:16:32
2010-03-16 01:16:54
2010-03-15 22:15:12
2010-03-15 22:15:17
2010-03-15 12:15:00
2010-03-15 11:15:35
2010-03-15 09:15:29
2010-03-15 18:15:42