我有一个构建包含字段集的表单的模块。我不想使用该<legend>
元素来呈现字段集标题,而是将此内容放在一个<div>
元素中。但我只想更改模块返回的表单的行为,因此我不想将任何新功能放入主题的 template.php 文件中。
在 mymod.module 我定义了:
// custom rendering function for fieldset elements
function theme_mymod_fieldset($element) {
return 'test';
}
// implement hook_theme
function mymod_theme() {
return array(
'mymod_fieldset' => array('arguments' => array('element' => NULL)),
'mymod_form' => array('arguments' => array())
);
}
// return a form that is based on the 'Basic Account Info' category of the user profile
function mymod_form() {
// load the user's profile
global $user;
$account = user_load($user->uid);
// load the profile form, and then edit it
$form_state = array();
$form = drupal_retrieve_form('user_profile_form', $form_state, $account, 'Basic Account Info');
// set the custom #theme function for this fieldset
$form['Basic Account Info']['#theme'] = 'mymod_fieldset';
// more form manipulations
// ...
return $form;
}
当我的页面被渲染时,我希望看到代表“基本帐户信息”的字段集被我的测试消息“测试”完全取代。相反,<fieldset>
and<legend>
元素被正常渲染,但字段集的主体被测试消息替换,如下所示:
<fieldset>
<legend>Basic Account Info</legend>
test
</fieldset>
为什么我的#theme 函数没有机会替换整个<fieldset>
元素?如果我在这个函数中包装一个文本字段,我可以完全替换<input>
元素及其标签。此外,如果我在我的站点的 template.php 中为 theme_fieldset 提供覆盖,它会按预期工作并且我能够完全替换<fieldset>
,所以我知道这是可能的。
为模块内的字段集提供#theme 函数有什么不同?