Drupal:如何使用CTools使字段集依赖

Drupal:如何使用CTools使字段集依赖,drupal,drupal-ctools,Drupal,Drupal Ctools,我正在使用Ctools依赖项使字段集可隐藏。这是我代码的一部分: $form['profile-status'] = array( '#type' => 'radios', '#title' => '', '#options' => array( 'new' => t('Create a new profile.'), 'select' => t('Use an existing profile.'),

我正在使用Ctools依赖项使字段集可隐藏。这是我代码的一部分:

$form['profile-status'] = array(
    '#type' => 'radios',
    '#title' => '',
    '#options' => array(
        'new' => t('Create a new profile.'),
        'select' => t('Use an existing profile.'),
    ),
);

$form['select'] = array(
    '#type' => 'select',
    '#title' => t('Select a profile'),
    '#options' => $options,
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:profile-status' => array('select')),
);

$form['profile-properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('View the profile'),
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:profile-status' => array('select')),
    '#input' => true,
);
在上面的代码片段中,有两个元素,一个选择元素和一个字段集。两者都有#进程和#依赖参数,并且都指向一个字段作为依赖值。问题是像select或textfield这样的元素很容易隐藏,但它不适用于fieldset。在支持请求页面中,CTools creator提到,
“#input”=>true
是一个解决方法。正如您所看到的,我将其添加到代码中,但它不起作用


你有什么建议吗?

在阅读了CTools的来源后,我找到了我的答案。字段集应更改为:

$form['profile-properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('View the profile'),
    '#process' => array('ctools_dependent_process'),
    '#dependency' => array('radio:profile-status' => array('select')),
    '#input' => true,

    '#id' => 'my-fs-id',
    '#prefix' => '<div id="my-fs-id-wrapper">',
    '#suffix' => '</div>',
);
$form['profile-properties']=数组(
“#类型”=>“字段集”,
“#title”=>t(“查看配置文件”),
“#进程”=>数组('ctools_-dependent_-process'),
“#依赖项”=>array('radio:profile status'=>array('select')),
“#输入”=>true,
“#id”=>“我的fs id”,
“#前缀”=>”,
“#后缀”=>”,
);
首先,必须为字段集设置ID。然后它必须被包装在一个DIV标签中。DIV的ID应该是feildset的ID,后缀为“-wrapper”。

现在(2013年2月)的用法是:

$form['foo_or_bar'] = array(
    '#title' => 'Foo or Bar',
    '#type' => 'radios',
    '#options' => array(
        "foo" => "Foo",
        "bar" => "Bar"
    ),
    '#default_value' => "foo",
);

$form['react_on_foo'] = array(
    '#type' => 'fieldset',
    '#title' => t('Foo fieldset'),
    '#dependency' => array('radio:foo_or_bar' => array('foo')),
);

$form['react_on_foo']['dummy_for_foo_fieldset'] = array(
    '#title' => t('Dummy for FOO fieldset'),
    '#type' => 'textfield',
);


$form['react_on_bar'] = array(
    '#type' => 'fieldset',
    '#title' => t('Bar fieldset'),
    '#dependency' => array('radio:foo_or_bar' => array('bar')),
);

$form['react_on_bar']['dummy_for_bar_fieldset'] = array(
    '#title' => t('Dummy for BAR fieldset'),
    '#type' => 'textfield',
);
而且#不再需要过程