0

我正在重构一些代码是我在某个时代编写的 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,
    );
4

1 回答 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
);

所以字段集是收音机的父级而不是对比

对你有帮助的跳

更新:
您可以使用 jquery 在字段集中附加无线电,如下所示

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

但它不是drupal方式

于 2011-09-30T11:48:14.337 回答