Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Description of Symfony2 form events?

This is the FormEvents class from Symfony2 repository on github. It's linked from the main article, How to Dynamically Generate Forms Using Form Events.

Anyone konws exactly when these events are called in the flow?

namespace Symfony\Component\Form;  /**  * @author Bernhard Schussek <[email protected]>  */ final class FormEvents {     const PRE_BIND = 'form.pre_bind';     const POST_BIND = 'form.post_bind';     const PRE_SET_DATA = 'form.pre_set_data';     const POST_SET_DATA = 'form.post_set_data';     const BIND_CLIENT_DATA = 'form.bind_client_data';     const BIND_NORM_DATA = 'form.bind_norm_data';     const SET_DATA = 'form.set_data'; } 
like image 391
Polmonino Avatar asked Mar 10 '12 23:03

Polmonino


People also ask

What are Symfony events?

The Symfony framework is an HTTP Request-Response one. During the handling of an HTTP request, the framework (or any application using the HttpKernel component) dispatches some events which you can use to modify how the request is handled and how the response is returned.

What is Symfony form?

A form is composed of fields, each of which are built with the help of a field type (e.g. TextType , ChoiceType , etc). Symfony comes standard with a large list of field types that can be used in your application.


1 Answers

There are two types of events:

DataEvent - read-only access to the form data. 'Pre' and 'Post' events are read-only.

FilterDataEvent - event that allows the form data to be modified.

form.pre_bind DataEvent triggered before data is bound to the form. Triggered by Symfony\Component\Form\Form::bind()

form.post_bind DataEvent triggered after data is bound to the form. Triggered by Symfony\Component\Form\Form::bind()

form.pre_set_data DataEvent triggered before fields are filled with default data. Triggered by Symfony\Component\Form\Form::setData()

form.post_set_data DataEvent triggered after fields are filled with default data. Triggered by Symfony\Component\Form\Form::setData()

form.bind_client_data FilterDataEvent triggered before data is bound to the form. Triggered by Symfony\Component\Form\Form::bind()

form.bind_norm_data FilterDataEvent triggered after data has been normalized. Triggered by Symfony\Component\Form\Form::bind(). See Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener (added by the UrlType for an example)

form.set_data FilterDataEvent triggered while default data is being bound. Triggered by Symfony\Component\Form\Form::setData()

I'd recommend poking around the Form class itself to get a better feel for when these events are triggered, and how you can use them.

like image 91
xanido Avatar answered Sep 19 '22 14:09

xanido