Drupal模块设置页面的构造

问题描述 投票:0回答:1

我重构某些代码是我在某个年龄写的Drupal模块。为了让其他人使用它,我添加了一个配置页面。

我已经成功定义了一个字段集,但是我不知道如何在其中“插入”内容。以下代码为我的站点上定义的每个节点类型设置了无线电:

        $node_types =   node_get_types('names');
    $test   =   array(
        '#title'            =>  t('tweeting node'),
        '#type'             =>  'radios',
        '#options'          =>  $node_types,
        '#default_value'    =>  'Page',
        '#weight'           =>  0,
    );

以下内容定义了我要将上面生成的单选按钮插入其中的字段集:

        $form['twitterhelper_nodecollection']   =   array(
        '#type'                             =>  'fieldset',
        '#title'                            =>  t('select a node'),
        '#weight'                           =>  0,
        '#collapsible'                      =>  TRUE,
        '#collapsed'                        => FALSE,
        '#parents'  =>  $test,
    );
drupal module fieldset
1个回答
3
投票

要在字段集中添加任何表单元素,您应该在字段集数组中插入此表单元素...

例如

$form['myfieldset'] = array( 
'#type' => 'fieldset' , 
'#collapsible' => TRUE ,
'#title' => t('My FIeldset'),
'#attributes' => array('id' => 'myfieldset-id'),
);

$form['myfieldset']['myradios'] = array(
'#type' => 'radios' , 
'#attributes' => array('id' =>'myradio-attributes') , 
....etc
);

因此字段集是无线电的父级而不是对比度

希望对您有帮助的人

UPDATE:您可以通过使用jquery将无线电附加到字段集内,如下所示

jQuery(document).ready(start) ; 
function start(){
  jQuery("#myradio-attributes").appendTo("#myfieldset-id"); 
  // i added this id by '#attributes'
}

但不是Drupal方式

© www.soinside.com 2019 - 2024. All rights reserved.