算是Drupal的HelloWorld吧,我对其做了中文注解:
<?php // $Id$ /** * @file * Administration page callbacks for the annotate module. */ /** * Form builder. * Configure annotations. * * @ingroup forms * * @see system_settings_form(). * */ function annotate_admin_settings () { // Get an array of node types with internal names as keys and // "friendly names" as values. E.g., // array('page' => 'Page', 'story' => 'Story') // 通过好懂的键值命名节点类型 $options = node_get_types('names');//node_get_types函数是一个非常重要的drupal函数。这个函数的作用是:得到节点的类型和名字 $form['annotate_node_types'] = array( '#type' => 'checkboxes', '#title' => t('Users may annotate these content types'),//在Drupal中所有的字符串都应该使用t()函数封装;它是Drupal的翻译函数,由于经常使用,为了方便,所以将其函数简写为“t” '#options' => $options, '#default_value' => variable_get('annotate_node_types',//当你的模块取回已存储的设置时,应该使用variable_get(),variable_get($name, $default = NULL) array( 'page' )), '#description' => t( 'A text field will be available on these content types to make user-specific notes.') ); return system_settings_form($form); }
<?php // $Id$ /** * @file * Lets users add private annotations to nodes. * * Adds a text field when a node is displayed * so that authenticated users may make notes. */ /** * Implementation of hook_menu(). */ function annotate_menu () { $items['admin/settings/annotate'] = array( //items数组是被聚合器aggregator用到的, //定义于globals.php, line 236,全局变量 'title' => 'Annotation 设置', 'description' => 'Change how annotations behave.', 'page callback' => 'drupal_get_form', 'page arguments' => array( 'annotate_admin_settings' ), 'access arguments' => array( 'administer site configuration' ), 'type' => MENU_NORMAL_ITEM, 'file' => 'annotate.admin.inc' ); return $items; }
如果是Drupal7的话,可能会得到一个Fatal error: Call to undefined function node_get_types() in \drupal\sites\all\modules\custom\annotate\annotate.admin.inc on line 22
这是因为drupal6和drupal7中有许多函数发生了改变。drupal6中node_get_types('names')对应dupal7中的node_type_get_names('names')更多详情参考:http://drupal.org/node/1121648