Drupal模块设置页面构建

发布于 2024-12-07 03:17:34 字数 925 浏览 3 评论 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,
    );

I am refactoring some code is a Drupal module I wrote sometime age. In order for others to use it, I am adding a configuration page.

I have successfully defined a fieldset but I don't know how to 'insert' content in to it.
The following code sets up radios for each node type defined on my site:

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

And the following defines my fieldset into which I want to insert the radio buttons generated above:

        $form['twitterhelper_nodecollection']   =   array(
        '#type'                             =>  'fieldset',
        '#title'                            =>  t('select a node'),
        '#weight'                           =>  0,
        '#collapsible'                      =>  TRUE,
        '#collapsed'                        => FALSE,
        '#parents'  =>  $test,
    );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木有鱼丸 2024-12-14 03:17:34

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

例如

$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 方式

to add any form element inside the fieldset you should insert this form element inside the field set array ...

E.g

$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
);

so the fieldset is the parent of the radios not the contrast

hop that help you

UPDATE:
you can append the radios inside the field set by using the jquery as the following

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

but its not the drupal way

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文