フィールドセットを含むフォームを構築するモジュールがあります。<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;
}
ページがレンダリングされると、「基本アカウント情報」を表すフィールドセットがテスト メッセージ「test」に完全に置き換えられることを期待していました。代わりに、<fieldset>
and<legend>
要素が通常どおりにレンダリングされますが、代わりにフィールドセットの本体が次のようにテスト メッセージに置き換えられます。
<fieldset>
<legend>Basic Account Info</legend>
test
</fieldset>
#theme 関数で<fieldset>
要素全体を置き換えることができないのはなぜですか? 代わりにこの関数でテキストフィールドをラップすると、<input>
要素をそのラベルとともに完全に置き換えることができます。さらに、自分のサイトの template.php で theme_fieldset のオーバーライドを提供すると、期待どおりに機能し、 を完全に置き換える<fieldset>
ことができるので、それが可能であることがわかります。
モジュール内のフィールドセットに #theme 関数を提供することの違いは何ですか?