Understanding FOSUserBundle form handler

Discuss Symfony 2 bundles here

Moderators: tiagojsag, dcobalt

Understanding FOSUserBundle form handler

Postby chris.zirkel » Sat Mar 31, 2012 5:36 pm

Hey

I want to understand the functionality of the FOSUserBundle form handling but I have some questions.

I don't understand the service xml file for each controller. Can anyone explain me the three service-blocks in this file: https://github.com/FriendsOfSymfony/FOS ... ration.xml

The next is in the issue is in the controller. For example https://github.com/FriendsOfSymfony/FOS ... roller.php
Code: Select all
        $form = $this->container->get('fos_user.registration.form');
        $formHandler = $this->container->get('fos_user.registration.form.handler');
        $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');


The form is already included in the handler, so why request here for the form from the service container?

The service id "fos_user.registration.form.handler" is used, but in the service file (registration.xml) the id is "fos_user.registration.form.handler.default"?
chris.zirkel
Member
 
Posts: 82
Joined: Fri Jul 22, 2011 2:51 am

Re: Understanding FOSUserBundle form handler

Postby blogsh » Sun Apr 01, 2012 4:50 pm

I haven't used FOSUserBundle yet, but I can give you "general" answers on your questions.

I don't understand the service xml file for each controller. Can anyone explain me the three service-blocks in this file: https://github.com/FriendsOfSymfony/FOS ... ration.xml

The first definition creates an instance of Symfony\Component\Form\Form called fos_user.registration.form. The class isn't instanciated directly with the new operator, but a factory is used. The factory form.factory is defined in https://github.com/symfony/symfony/blob ... g/form.xml
The class is https://github.com/symfony/symfony/blob ... actory.php and FOSUserBundle uses the createNamed method to create a new form object.

The next one is "fos_user.registration.form.type". It defines a class the represents a new FormType. The tag "form.type" tells the Form component to register this type with the name "fos_user_registration". This means you can use this alias in the form component:
Code: Select all
$formBuilder
    ->add('created', 'date')
    ->add('registration', 'fos_user_registration');


The last service is a simple instance that is used later in the bundle.

The form is already included in the handler, so why request here for the form from the service container?

Why not? :) You could also add a method "getForm" to the handler and get the form this way. I think at the end both ways are okay, but you have to decide for one :)

The service id "fos_user.registration.form.handler" is used, but in the service file (registration.xml) the id is "fos_user.registration.form.handler.default"?

"fos_user_registration.form.handler" is only an alias that points to the actual implementation. You can define your own handler in the configuration:
https://github.com/FriendsOfSymfony/FOS ... n.php#L127
blogsh
Faithful Member
 
Posts: 501
Joined: Thu Mar 03, 2011 9:35 pm
Location: Germany

Re: Understanding FOSUserBundle form handler

Postby chris.zirkel » Sun Apr 01, 2012 7:52 pm

blogsh wrote:
The form is already included in the handler, so why request here for the form from the service container?

Why not? :) You could also add a method "getForm" to the handler and get the form this way. I think at the end both ways are okay, but you have to decide for one :)


Okay, the form instance is the same instance as in the handler?
chris.zirkel
Member
 
Posts: 82
Joined: Fri Jul 22, 2011 2:51 am

Re: Understanding FOSUserBundle form handler

Postby blogsh » Tue Apr 03, 2012 7:02 pm

As far as I can see, yes. Maybe the parameters is modified in the Extension class or in a CompilerPass, but I don't think so (and I haven't got the time to look them thorugh atm, will have a look at it later).
blogsh
Faithful Member
 
Posts: 501
Joined: Thu Mar 03, 2011 9:35 pm
Location: Germany


Return to Bundles discussion

Who is online

Users browsing this forum: No registered users and 2 guests