学习写一个Drupal模块。编写一个.info模块信息文件,文件名要与模块的名字相同。
name = Annotate //模块名
description = "Allows users to annotate nodes." //关于这个模块的描述
package = Pro Drupal Development //我的理解类似与于命名空间,也就是该模块属于哪一个类型
core = 7.x
files[] = annotate.module //files数组是与这个模块相关联的文件
files[] = annotate.install
files[] = annotate.admin.inc
configure=admin/config/content/annotate/settings
编写.module文件
First, we’ll define a path where we can access our settings. Then, we’ll create the settings form. To make a path, I need to implement a hook,specifically hook_menu.
首先要定义一个我们能够设置的路径,然后创建一个设置表单页面。
hook_menu() 定义管理员菜单项
function annotate_menu() {
$items['admin/config/annotate'] = array(
'title' => 'Node annotation',
'description' => 'Adjust node annotation options.',
'position' => 'right',
'weight' => -5,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/config/annotate/settings'] = array(
'title' => 'Annotation settings', //链接名称
'description' => 'Change how annotations behave.', //描述
'page callback' => 'drupal_get_form', //应该是生成表单的函数
'page arguments' => array('annotate_admin_settings'), //表单ID
'access arguments' => array('administer site configuration'), //后台页面配置权限 就是能访问配置页面
'type' => MENU_NORMAL_ITEM,
'file' => 'annotate.admin.inc',
);
return $items;
}