Skip to content

Commit

Permalink
Changed the way to configure the forms
Browse files Browse the repository at this point in the history
  • Loading branch information
stof committed Jul 8, 2011
1 parent 8120344 commit cc43aa9
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 81 deletions.
20 changes: 10 additions & 10 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ private function addProfileSection(ArrayNodeDefinition $node)
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue('FOS\UserBundle\Form\Type\ProfileFormType')->end()
->scalarNode('handler')->defaultValue('FOS\UserBundle\Form\Handler\ProfileFormHandler')->end()
->scalarNode('type')->defaultValue('fos_user_profile')->end()
->scalarNode('handler')->defaultValue('fos_user.profile.form.handler.default')->end()
->scalarNode('name')->defaultValue('fos_user_profile_form')->cannotBeEmpty()->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
Expand Down Expand Up @@ -112,8 +112,8 @@ private function addRegistrationSection(ArrayNodeDefinition $node)
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue('FOS\UserBundle\Form\Type\RegistrationFormType')->end()
->scalarNode('handler')->defaultValue('FOS\UserBundle\Form\Handler\RegistrationFormHandler')->end()
->scalarNode('type')->defaultValue('fos_user_registration')->end()
->scalarNode('handler')->defaultValue('fos_user.registration.form.handler.default')->end()
->scalarNode('name')->defaultValue('fos_user_registration_form')->cannotBeEmpty()->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
Expand Down Expand Up @@ -151,8 +151,8 @@ private function addResettingSection(ArrayNodeDefinition $node)
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue('FOS\UserBundle\Form\Type\ResettingFormType')->end()
->scalarNode('handler')->defaultValue('FOS\UserBundle\Form\Handler\ResettingFormHandler')->end()
->scalarNode('type')->defaultValue('fos_user_resetting')->end()
->scalarNode('handler')->defaultValue('fos_user.resetting.form.handler.default')->end()
->scalarNode('name')->defaultValue('fos_user_resetting_form')->cannotBeEmpty()->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
Expand All @@ -176,8 +176,8 @@ private function addChangePasswordSection(ArrayNodeDefinition $node)
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue('FOS\UserBundle\Form\Type\ChangePasswordFormType')->end()
->scalarNode('handler')->defaultValue('FOS\UserBundle\Form\Handler\ChangePasswordFormHandler')->end()
->scalarNode('type')->defaultValue('fos_user_change_password')->end()
->scalarNode('handler')->defaultValue('fos_user.change_password.form.handler.default')->end()
->scalarNode('name')->defaultValue('fos_user_change_password_form')->cannotBeEmpty()->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
Expand Down Expand Up @@ -248,8 +248,8 @@ private function addGroupSection(ArrayNodeDefinition $node)
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue('FOS\UserBundle\Form\GroupFormType')->end()
->scalarNode('handler')->defaultValue('FOS\UserBundle\Form\GroupFormHandler')->end()
->scalarNode('type')->defaultValue('fos_user_group')->end()
->scalarNode('handler')->defaultValue('fos_user.group.form.handler.default')->end()
->scalarNode('name')->defaultValue('fos_user_group_form')->cannotBeEmpty()->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
Expand Down
40 changes: 15 additions & 25 deletions DependencyInjection/FOSUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,19 @@ public function load(array $configs, ContainerBuilder $container)
if (!empty($config['profile'])) {
$loader->load('profile.xml');

$container->setParameter('fos_user.profile.form.validation_groups', $config['profile']['form']['validation_groups']);
unset($config['profile']['form']['validation_groups']);
$container->setParameter('fos_user.profile.form.name', $config['profile']['form']['name']);
unset($config['profile']['form']['name']);
$container->setAlias('fos_user.profile.form.handler', $config['profile']['form']['handler']);
unset($config['profile']['form']['handler']);

$this->remapParametersNamespaces($config['profile'], $container, array(
'form' => 'fos_user.profile.form.%s.class',
'form' => 'fos_user.profile.form.%s',
));
}

if (!empty($config['registration'])) {
$loader->load('registration.xml');

$container->setParameter('fos_user.registration.form.validation_groups', $config['registration']['form']['validation_groups']);
unset($config['registration']['form']['validation_groups']);
$container->setParameter('fos_user.registration.form.name', $config['registration']['form']['name']);
unset($config['registration']['form']['name']);
$container->setAlias('fos_user.registration.form.handler', $config['registration']['form']['handler']);
unset($config['registration']['form']['handler']);

if (!empty($config['registration']['confirmation']['from_email'])) {
$container->setParameter(
Expand All @@ -109,30 +105,26 @@ public function load(array $configs, ContainerBuilder $container)

$this->remapParametersNamespaces($config['registration'], $container, array(
'confirmation' => 'fos_user.registration.confirmation.%s',
'form' => 'fos_user.registration.form.%s.class',
'form' => 'fos_user.registration.form.%s',
));
}

if (!empty($config['change_password'])) {
$loader->load('change_password.xml');

$container->setParameter('fos_user.change_password.form.validation_groups', $config['change_password']['form']['validation_groups']);
unset($config['change_password']['form']['validation_groups']);
$container->setParameter('fos_user.change_password.form.name', $config['change_password']['form']['name']);
unset($config['change_password']['form']['name']);
$container->setAlias('fos_user.change_password.form.handler', $config['change_password']['form']['handler']);
unset($config['change_password']['form']['handler']);

$this->remapParametersNamespaces($config['change_password'], $container, array(
'form' => 'fos_user.change_password.form.%s.class',
'form' => 'fos_user.change_password.form.%s',
));
}

if (!empty($config['resetting'])) {
$loader->load('resetting.xml');

$container->setParameter('fos_user.resetting.form.validation_groups', $config['resetting']['form']['validation_groups']);
unset($config['resetting']['form']['validation_groups']);
$container->setParameter('fos_user.resetting.form.name', $config['resetting']['form']['name']);
unset($config['resetting']['form']['name']);
$container->setAlias('fos_user.resetting.form.handler', $config['resetting']['form']['handler']);
unset($config['resetting']['form']['handler']);

if (!empty($config['resetting']['email']['from_email'])) {
$container->setParameter(
Expand All @@ -147,24 +139,22 @@ public function load(array $configs, ContainerBuilder $container)
'token_ttl' => 'fos_user.resetting.token_ttl',
),
'email' => 'fos_user.resetting.email.%s',
'form' => 'fos_user.resetting.form.%s.class',
'form' => 'fos_user.resetting.form.%s',
));
}

if (!empty($config['group'])) {
$loader->load('group.xml');
$loader->load(sprintf('%s_group.xml', $config['db_driver']));

$container->setParameter('fos_user.form.group.validation_groups', $config['group']['form']['validation_groups']);
unset($config['group']['form']['validation_groups']);
$container->setParameter('fos_user.form.group.name', $config['group']['form']['name']);
unset($config['group']['form']['name']);
$container->setAlias('fos_user.group.form.handler', $config['group']['form']['handler']);
unset($config['group']['form']['handler']);

$this->remapParametersNamespaces($config['group'], $container, array(
'' => array(
'group_class' => 'fos_user.model.group.class',
),
'form' => 'fos_user.form.%s.group.class',
'form' => 'fos_user.group.form.%s',
));
}
}
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/change_password.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<services>

<service id="fos_user.change_password.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument type="service" id="fos_user.change_password.form.type" />
<argument>%fos_user.change_password.form.type%</argument>
<argument>%fos_user.change_password.form.name%</argument>
<argument />
<argument type="collection">
Expand All @@ -16,11 +16,11 @@
</argument>
</service>

<service id="fos_user.change_password.form.type" class="%fos_user.change_password.form.type.class%">
<tag name="form.type" />
<service id="fos_user.change_password.form.type" class="FOS\UserBundle\Form\Type\ChangePasswordFormType">
<tag name="form.type" alias="fos_user_change_password" />
</service>

<service id="fos_user.change_password.form.handler" class="%fos_user.change_password.form.handler.class%" scope="request">
<service id="fos_user.change_password.form.handler.default" class="FOS\UserBundle\Form\Handler\ChangePasswordFormHandler" scope="request">
<argument type="service" id="fos_user.change_password.form" />
<argument type="service" id="request" />
<argument type="service" id="fos_user.user_manager" />
Expand Down
16 changes: 8 additions & 8 deletions Resources/config/group.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

<services>

<service id="fos_user.form.group" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument type="service" id="fos_user.form.type.group" />
<argument>%fos_user.form.group.name%</argument>
<service id="fos_user.group.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument>%fos_user.group.form.type%</argument>
<argument>%fos_user.group.form.name%</argument>
<argument />
<argument type="collection">
<argument key="data_class">%fos_user.model.group.class%</argument>
<argument key="validation_groups">%fos_user.form.group.validation_groups%</argument>
<argument key="validation_groups">%fos_user.group.form.validation_groups%</argument>
</argument>
</service>

<service id="fos_user.form.type.group" class="%fos_user.form.type.group.class%">
<tag name="form.type" />
<service id="fos_user.group.form.type" class="FOS\UserBundle\Form\Type\GroupFormType">
<tag name="form.type" alias="fos_user_group" />
</service>

<service id="fos_user.form.handler.group" class="%fos_user.form.handler.group.class%" scope="request">
<argument type="service" id="fos_user.form.group" />
<service id="fos_user.group.form.handler.default" class="FOS\UserBundle\Form\Handler\GroupFormHandler" scope="request" public="false">
<argument type="service" id="fos_user.group.form" />
<argument type="service" id="request" />
<argument type="service" id="fos_user.group_manager" />
</service>
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<services>

<service id="fos_user.profile.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument type="service" id="fos_user.profile.form.type" />
<argument>%fos_user.profile.form.type%</argument>
<argument>%fos_user.profile.form.name%</argument>
<argument />
<argument type="collection">
Expand All @@ -16,11 +16,11 @@
</argument>
</service>

<service id="fos_user.profile.form.type" class="%fos_user.profile.form.type.class%">
<tag name="form.type" />
<service id="fos_user.profile.form.type" class="FOS\UserBundle\Form\Type\ProfileFormType">
<tag name="form.type" alias="fos_user_profile" />
</service>

<service id="fos_user.profile.form.handler" class="%fos_user.profile.form.handler.class%" scope="request">
<service id="fos_user.profile.form.handler.default" class="FOS\UserBundle\Form\Handler\ProfileFormHandler" scope="request" public="false">
<argument type="service" id="fos_user.profile.form" />
<argument type="service" id="request" />
<argument type="service" id="fos_user.user_manager" />
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<services>

<service id="fos_user.registration.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument type="service" id="fos_user.registration.form.type" />
<argument>%fos_user.registration.form.type%</argument>
<argument>%fos_user.registration.form.name%</argument>
<argument />
<argument type="collection">
Expand All @@ -16,11 +16,11 @@
</argument>
</service>

<service id="fos_user.registration.form.type" class="%fos_user.registration.form.type.class%">
<tag name="form.type" />
<service id="fos_user.registration.form.type" class="FOS\UserBundle\Form\Type\RegistrationFormType">
<tag name="form.type" alias="fos_user_registration" />
</service>

<service id="fos_user.registration.form.handler" class="%fos_user.registration.form.handler.class%" scope="request">
<service id="fos_user.registration.form.handler.default" class="FOS\UserBundle\Form\Handler\RegistrationFormHandler" scope="request" public="false">
<argument type="service" id="fos_user.registration.form" />
<argument type="service" id="request" />
<argument type="service" id="fos_user.user_manager" />
Expand Down
8 changes: 4 additions & 4 deletions Resources/config/resetting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<services>

<service id="fos_user.resetting.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument type="service" id="fos_user.resetting.form.type" />
<argument>%fos_user.resetting.form.type%</argument>
<argument>%fos_user.resetting.form.name%</argument>
<argument />
<argument type="collection">
Expand All @@ -16,11 +16,11 @@
</argument>
</service>

<service id="fos_user.resetting.form.type" class="%fos_user.resetting.form.type.class%">
<tag name="form.type" />
<service id="fos_user.resetting.form.type" class="FOS\UserBundle\Form\Type\ResettingFormType">
<tag name="form.type" alias="fos_user_resetting" />
</service>

<service id="fos_user.resetting.form.handler" class="%fos_user.resetting.form.handler.class%" scope="request">
<service id="fos_user.resetting.form.handler.default" class="FOS\UserBundle\Form\Handler\ResettingFormHandler" scope="request" public="false">
<argument type="service" id="fos_user.resetting.form" />
<argument type="service" id="request" />
<argument type="service" id="fos_user.user_manager" />
Expand Down
Loading

0 comments on commit cc43aa9

Please sign in to comment.