FOSUserBundle
FOSUserBundle copied to clipboard
Add a chapter about extending and overwriting the validation
The chapter should describe how to add its own rules by keeping the bundle ones and also how to validate without the bundle rules.
So, could you explain how can I do it? :)
i have my own register form type. now i won't remove the password notblank constraint when the user token is a special class in my case a oauth class. So i have get it work with:
- override the service definition and remove the validation group.
<service id="fos_user.registration.form" factory-method="createNamed" factory-service="form.factory" class="Symfony\Component\Form\Form">
<argument>%fos_user.registration.form.type%</argument>
<argument>%fos_user.registration.form.name%</argument>
<argument />
<argument type="collection">
</argument>
</service>
- use the getDefaultOptions method to switch to the Profile or another validation_group
<?php
public function getDefaultOptions(array $options)
{
$options = parent::getDefaultOptions($options);
$tokenUser = $this->context->getToken()->getUser();
if ($tokenUser instanceof $this->oauthUserClass) {
$options['validation_groups'] = array('Profile');
}
return $options;
}
Questions:
Why is the validation group name not set in the form types getDefaultOptions method?
+1
I need this too :+1:
:+1:
Maybe it's too late, but would it be possible for the 2.x version to move the default constraints group to a prefixed name? For example, the Registration group could be renamed FOS_Registration. This is because there is currently no way for Symfony to override the constraints in a child class, and the current group names imho are too common and general to be used by the bundle instead of the application itself.