You are here

添加特定于模块的设置(1)

g089h515r806 的头像
Submitted by g089h515r806 on 星期二, 2009-07-28 12:11

     Drupal有多种不同的节点类型(在用户界面称之为内容类型),比如Story和Page。我们想将注释的使用限定在特定的一些节点类型上。为了实现这一点,我们需要创建一个页面,在里面告诉我们的模块我们想注释哪些节点类型。在该页面,我们将呈现一组复选框,每一个复选框就对应一个已有的内容类型。这样终端用户就可以通过选中或者取消选中复选框(如图2-1所示),就可以决定哪些内容类型可被注释。这样的页面就是一个管理页面,只有在需要的时候才加载和解析合成该页面的代码。因此,我们把代码放在了一个单独的文件中,而不是放在我们的annotate.module文件里,而对于每个web请求,都会加载和运行annotate.module文件。由于我们告诉了Drupal,在文件annotate.admin.inc中查找我们的设置表单,所以创建文件sites/all/modules/custom/annotate/annotate.admin.inc,并向里面添加以下代码:

 
<?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');
 
    $form['annotate_node_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Users may annotate these content types'),
        '#options' => $options,
        '#default_value' => variable_get('annotate_node_types', array('page')),
        '#description' => t('A text field will be available on these content types          to make user-specific notes.'),
    );
 
    return system_settings_form($form);
}
 
 老葛的Drupal培训班 Think in Drupal

Drupal版本:

评论

17qqnet 的头像

1