特別で複雑な目的のために新しいフォーム要素クラスを作成しました(「検索ウィザード」ポップアップを開くためのアドオンボタン付きのテキスト入力フィールド)。
この要素を適切にレンダリングするために、フォームビューヘルパーも作成しました。これまでのところ、すべてが機能し、問題ありません。
ただし、FormCollectionビューヘルパーを使用してフォームをレンダリングしようとすると、要素は基本的な入力要素としてレンダリングされます。これは、FormCollectionヘルパーが依存するFormElementビューヘルパーが、ハードコードされた一連のif句を使用して、要素のタイプを特定のフォームビューヘルパーにマップするためです。要素のクラスをマップできないため、にフォールバックしFormInput
ます。
つまり(Zend / Form / View / Helper / FormElement.php、41〜49行目から取得):
if ($element instanceof Element\Button) {
$helper = $renderer->plugin('form_button');
return $helper($element);
}
if ($element instanceof Element\Captcha) {
$helper = $renderer->plugin('form_captcha');
return $helper($element);
}
...
$helper = $renderer->plugin('form_input');
return $helper($element);
等々。
このアーキテクチャは実際には拡張性を促進しないため、ここで少し立ち往生しています。
私が思いついた唯一の解決策(手動でフォームをレンダリングすることを除く)は、FormElementビューヘルパークラスを拡張して、独自のCustomFormElementビューヘルパーを作成することです。ただし、その複雑さのために、カスタム要素を独自のモジュールに配置しました。したがって、このCustomFormElementヘルパーを動的に記述して、任意のモジュールからカスタム要素を追加する必要があります。これは推奨される手順ではないと思います。
別の解決策はありますか、それとも私の完全なアプローチでさえ推奨されていませんか?前もって感謝します!