Skip to content

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

Closed
wants to merge 7 commits into from

Conversation

khepin
Copy link
Contributor

@khepin khepin commented Oct 22, 2012

No description provided.


.. code-block:: php

private $security_context;
Copy link
Member

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

@khepin
Copy link
Contributor Author

khepin commented Oct 22, 2012

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.
Copy link
Member

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

@weaverryan
Copy link
Member

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!

@khepin
Copy link
Contributor Author

khepin commented Oct 30, 2012

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 = [
Copy link
Member

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(
    ...,
);

@weaverryan
Copy link
Member

Hey Sebastien!

This is a very complete example :). But I have a few questions first!

  1. I still think we have some repetition between the original part of this entry and your part. The first part talks about using posted data to dynamically change the form. You talk about this as well - and also show using a userId instead of the submitted data. I think we need to merge the two examples - there should probably only be one example using the PRE_SET_DATA in this way.

  2. There are some whitespace differences as well in the file - probably due to line break differences.

  3. Merging the 2 parts of this entry may solve it, but we may have too many other details. For example, showing the user how to register a form as a service and use it in the controller should be here. The goal is to be as "dense" with new information as possible (while still making it a full "story"). The less other details, the more we can get the "meat" of this entry across to the user. Nobody actually likes reading - so shorter = better ;)

Thanks!

@wouterj
Copy link
Member

wouterj commented Feb 2, 2013

ping @khepin

@khepin
Copy link
Contributor Author

khepin commented Feb 7, 2013

Yikes, been a while!
I removed the parts of the article that duplicate something that is explained elsewhere.

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.

@weaverryan
Copy link
Member

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!

@weaverryan weaverryan closed this Mar 30, 2013
weaverryan added a commit that referenced this pull request Mar 30, 2013
weaverryan added a commit that referenced this pull request Apr 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants