-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add more concise signature to FormInterface::add() #5806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm all 👍 |
@mvrhov the FormBuilder does not use func_get_args, simply an optional second argument |
I really like the idea 👍 addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { if (/* some condition */) { $event->getForm()->addField('myfield', 'text'); //$event->getForm()->add('myfield', 'text'); } else { $event->getForm()->remove('myfield'); } }); |
This PR was merged into the master branch. Commits ------- 19d8510 [Form] Improved Form::add() and FormBuilder::add() to accept integers as field names fb71964 [Form] Added an alternative signature Form::add($name, $type, $options) Discussion ---------- [Form] Added an alternative signature Form::add($name, $type, $options) Bug fix: no Feature addition: yes Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: #5806 Todo: - License of the code: MIT Documentation PR: symfony/symfony-docs#2024 --------------------------------------------------------------------------- by bschussek at 2012-12-18T10:42:55Z ping @fabpot
Right now, the addition of fields in event listeners is quite complicated, because
FormInterface
does not support the same concise syntax for adding fields likeFormBuilderInterface
does:This can be simplified by matching the signature of
FormInterface::add()
withFormBuilderInterface::add()
:The method, like
FormBuilderInterface::add()
, would then support both signatures:add($name, $type, array $options = array())
add(FormInterface $child)
The text was updated successfully, but these errors were encountered: