フォームからfieldsetを丸ごと削除する

アカウント情報のEditから、以下の部分を丸ごと取り除きたい。

1.フォームのIDを調べる
ソースコードからformタグを見つけて、そのid属性を確認する。

<form action="/en/user/1/edit"  
  accept-charset="UTF-8" 
  method="post" 
  id="user-profile-form" 
  enctype="multipart/form-data">

であれば、idは「user-profile-form」

2.単純かカスタムモジュールを作成し、そのフォームに対するform_alter()を作成する

function <モジュール名>_form_<フォームID>_alter(&$form, &$form_state) {
}

例えばモジュール名が「formchange」でフォームのIDが「user-profile-form」の場合は

function tm_custom_form_user_profile_form_alter(&$form, &$form_state) {
}

のように。これでそのフォームに対して直接タッチできるようになる。

3.削除したいフィールドセットの要素名をゲットする
HTMLのソースコードには<fieldset>のようにIDも何もついていないため、この特定の要素が内部で何のIDが振られているか確認する。print_rで$formの中身を確認。

function tm_custom_form_user_profile_form_alter(&$form, &$form_state) {
  print_r($form);
}

そうすると、

Array
(
    [locale] => Array
        (
            [#type] => fieldset
            [#title] => Language settings
            [#weight] => 1
            [language] => Array
                (
                    [#type] => radios
                    [#title] => Language
                    [#default_value] => en
                    [#options] => Array
                        (
                            [en] => English
                            [ja] => Japanese (日本語)
                        )

                    [#description] => This account's default language for e-mails, and preferred language for site presentation.
                )

        )

    [signature_settings] => Array
        (
    続く・・・

のように、どうもこの要素は[signature_settings]として処理されていることがわかる。

4.unsetする
その要素名に対して、unsetをかける

function tm_custom_form_user_profile_form_alter(&$form, &$form_state) {
  unset( $form['signature_settings'] );
}

これでそのフィールドセットはきれいに無くなっている。