web-dev-qa-db-ja.com

hook_form_user_register_form_alter()はユーザー登録フォームをカスタマイズしません

hook_form_user_register_form_alter()を実装しました。

_function hook_form_user_register_form_alter($form, $form_state, $form_id) {
  $form['account']['name']['#description'] = 'This is your login name. It will be displayed on the forums and in comments. This is not your billing information. Spaces are allowed; punctuation is not allowed except for periods, hyphens, apostrophes, and underscores.';
  $form['actions']['submit']['#value'] = 'Continue to subscription and payment page.';
  $form['#submit'][] = 'custom_user_register_submit';

  dpm($form);
}
_

登録ページを使用すると、さまざまな結果が表示されます。まず、送信ボタンをクリックすると、custom_user_register_submit()関数が呼び出されます。これは正しいです。

ただし、ユーザー登録ページに印刷されるフォーム要素に変更はありません。たとえば、ボタンにはカスタムテキストが必要です。ありません。デフォルトのテキスト「create new account」を使用します。奇妙なことに、私のdpm()の出力では、これらの配列要素の値が私のカスタムコードと一致しています。したがって、私のフックは正しく実装され、フォーム要素が変更されているように見えますが、Drupalブートストラップで後ほど、それらは再びオーバーライドされ、デフォルトに戻されます。

誰かが解決策を知っていますか?

2
sheldonkreger

すべてのDrupal __alter_フックについては、変更する必要がある変数を参照として渡す必要があります。

関数の宣言では、_$form_は_&$form_である必要があります。これにより、PHP関数のスコープの場合、その変数の参照が内部に渡されるため、_$form_配列に加えた変更が保持されます。

したがって、関数宣言は次のようになります(両方の変数を変更するため):hook_form_user_register_form_alter(&$form, &$form_state)

7
AyeshK