Le 26/05/2011 21:49, thesaint a écrit :
I'm having a hard time understanding how the new form system really
*works*. I understand the examples from the book and have no problem
customizing the form templates. But how the different classes relate
to each other, what class creates what effect, I have no idea. It
would be cool to have some kind of explanation of the "Form life
cycle" in the documentation. Some basic reference that goes beyond the
question "how to build a form get get a value object from it" but is
more concise than reading the code of the form classes.

Here are some questions that may form the basis for such a document
(or just document my cluelessness)
- What happens when a form builder is invoked?
- How is it invoked?
- What's the difference between the user defined form type (inheriting
from AbstractType) and the Form class?
The types are about defining a type of field (be it a simple text input or a complex type representing your whole object). The Form class is the object representing *one* form with some specific data and created using the types.
- What's the purpose of FormTypeInterface::getParent? Why not use
Reflection and checking for inheritance?
the getParent method says how the type should be rendered if there is no widget defined specifically for it. It will use the widget of the parent (and so on). This is not the same as object inheritance of the type as this can change according to some options. For instance, the DateType will configure the parent to /field/ when it is rendered as a single input field but will set it to /form/ when being rendered as 3 separate input fields as it contains several fields in this case.
- How are the parent-child-relationships of FormType used?
- What is FormTypeExtensionInterface (and the abstract class) for?
Extensions are about providing a way to add a set of new types easily when using the Form component outside the framework. This is not used when using the framework as registering the type directly has better perfomances than using an extension and the DI container allows to do it easily.
- How are the different parameters for the Form constructor collected?
the Form instance is created by the FormBuilder (which gets some of them from the FormFactory which created the FormBuilder). Creating the Form instance without using the FormBuilder is not a supported use case and you are on your own if you choose to go this way (which is absolutely not easy).
- What happens when "bind" is invoked? In the end, the values given to
"bind" are set in the data object, but what happens from the "bind"
call until the setYYY mtehod of the data object is called?
Data are transformed according to the types (an IntegerType would convert it to a PHP integer and throw a TransformationFailedException if the data passed to the field is not an integer which would add an error for the form). The data are also normalized using the normalizers. and finally, at the end of the bind() method the validator is called to validate the object. And many form events are dispatched to the listeners registered in the form to provide hooks at each step of the process.
- What events occur in the form lifecycle and how can I hook into
these events?
The list of available events is here: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Events.php You can look at the code of the Form class to see when each event is dispatched as this is not documented yet.

Listeners are registered through the FormBuilder
- How does the FormView class work? How does it assemble the view for
a form?
the FormView is the object you get in the template. A type can set some custom variable in the FormView which will be available when rendering this Form instance. And of course, it contains the data about which type is represented (to choose the good widget), and about the data in the form (to display the value, the errors...)

--
Christophe | Stof

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to