【问题标题】:Drupal module settings page constructionDrupal 模块设置页面构建
【发布时间】:2011-11-28 09:14:35
【问题描述】:

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

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

    例如

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      相关资源
      最近更新 更多