-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
add cookbook entry on creating dynamic forms based on services #1842
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
Conversation
|
||
.. code-block:: php | ||
|
||
private $security_context; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use camelCased variable names
Needs to check the php version of the configuration. |
context, or by defining it as a service. This is the option we will show here. | ||
|
||
To define your form as a service, you simply add the configuration to your | ||
``config.yml`` file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you use different formats you can't use a specific extension in your text. Use something like '... add the confguration to your configuration file.' And add file comments in all code blocks below:
yaml file
# app/config/config.yml
xml file
<!-- app/config/config.xml -->
php file
// app/config/config.php
Hi Sebastien! Cool, a whole new entry! :) First thing though, how do you see this as different/similar to http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html? If it's not different, should we combine the entries? Was the existing article not easy enough to find (<-- this is very possible). Also, the existing entry uses a subscriber (i.e. a whole other class for the listener), whereas your entry uses an anonymous function. I would much rather show the user how to do this using an anonymous function, and then just mention that this logic could also be in its own class. So, at the very least, that's one piece of your entry that I think we definitely need to integrate. Let me know what you think and we'll go from there! I think this is a very important topic, so I would like to get this done well. Thanks! |
…form configuration
I have merged the two articles. I have added another section for some more advanced use of the form events and dynamic generation. In that last case, using closures wouldn't make sense. So I think it's good to keep both on the cookbook entry so users know what are the different options. |
$form = $event->getForm(); | ||
$userId = $user->getId(); | ||
|
||
$form_options = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to use the backwards comtable way of defining PHP arrays instead of the PHP5.4 way:
$form_options = array(
...,
);
Hey Sebastien! This is a very complete example :). But I have a few questions first!
Thanks! |
ping @khepin |
…e in the book or cookbook
Yikes, been a while! I kept all the examples as I feel they fit different use cases and sticking all of them together would create confusion. Let me know what you think. |
Hey Sebastien! Thanks for the updates on this, I've finally just merged it into the 2.1 branch. I'll have another PR coming shortly with some tweaks as I wanted to re-read this big chapter anyways. Thanks! |
…e is still quite a bit left to do
…e is still quite a bit left to do
No description provided.