This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Form
Fabien Potencier 4f3e7bb698 merged branch canni/enable_validation_groups_callback (PR #2498)
Commits
-------

d08ec5e Add DelegatingValidator tests
e1822e7 Enable dynamic set of validation groups by a callback or Closure

Discussion
----------

[Form][Validator] Enable dynamic set of validation groups based on callback

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Symfony2 tests written for new feature: yes
closes tickets: #2498 #1151

This will allow developer to pass a Closure or a callback array as a Validation groups option of a form. Eg:

```
class ClientType extends AbstarctType
{
// ...
    public function getDefaultOptions(array $options)
    {
        return array(
            'validation_groups' => function(FormInterface $form){
                // return array of validation groups based on submitted user data (data is after transform)
                $data = $form->getData();
                if($data->getType() == Entity\Client::TYPE_PERSON)
                    return array('Default', 'person');
                else
                    return array('Default', 'company');
            },
        );
    }
// ...
}
```

```
class ClientType extends AbstarctType
{
// ...
    public function getDefaultOptions(array $options)
    {
        return array(
            'validation_groups' => array(
                'Acme\\AcmeBundle\\Entity\\Client',
                'determineValidationGroups'
            ),
        );
    }
// ...
}
```

This will make developers life easier !

---------------------------------------------------------------------------

by schmittjoh at 2011/10/27 06:39:56 -0700

Does that work if your ClientType were added to another form type?

e.g.

```php
<?php

class MyComplexType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('client', new ClientType());
    }

    // ...
}
```

---------------------------------------------------------------------------

by canni at 2011/10/27 06:44:33 -0700

This is doing nothing more than injecting array of validation groups, should work, but I have not tested this use case.

---------------------------------------------------------------------------

by canni at 2011/10/28 01:58:26 -0700

PHPUnit output

```
OK, but incomplete or skipped tests!
Tests: 5011, Assertions: 12356, Incomplete: 36, Skipped: 32.
```

---------------------------------------------------------------------------

by canni at 2011/11/02 11:37:47 -0700

Now functionality is complete, test are written, and implementation is clean. :)

---------------------------------------------------------------------------

by stloyd at 2011/11/02 11:50:44 -0700

Can tou `squash` your commits ? Thanks.

---------------------------------------------------------------------------

by canni at 2011/11/02 11:58:41 -0700

Done

---------------------------------------------------------------------------

by fabpot at 2011/11/07 07:51:18 -0800

Can you add some tests for the `DelegatingValidator` class, which is where we can ensure that the new feature actually works as expected?

---------------------------------------------------------------------------

by canni at 2011/11/07 13:53:16 -0800

OK, I've written proof-of-concept tests, also I've squashed few commits to make things clear.
Personally I think this should go straight into 2.0 series, as it do not beak BC, and a feature is really nice to use.

---------------------------------------------------------------------------

by stof at 2011/11/07 14:17:15 -0800

@canni the 2.0 branch is for bug fixes, not for new features. This is the difference between maintenance releases and minor releases.
2011-11-08 09:05:41 +01:00
..
Event fixed CS 2011-06-08 12:16:48 +02:00
Exception [Form] simplified previous merge and fixed unit test 2011-07-04 12:13:46 +02:00
Extension merged branch canni/enable_validation_groups_callback (PR #2498) 2011-11-08 09:05:41 +01:00
Guess fixed CS 2011-06-08 12:16:48 +02:00
Resources/config [Form] Fix DelegatingValidator namespace 2011-04-23 23:20:56 -07:00
Util [Form] Simplified a bit FormUtil and extended test coverage 2011-10-07 12:04:26 +02:00
AbstractExtension.php Remove useless code 2011-07-04 14:08:20 +02:00
AbstractType.php [Form] Fixed a typo in AbstractType phpdoc 2011-08-13 13:43:13 +02:00
AbstractTypeExtension.php Merge branch 'master' into form-phpdoc-2 2011-05-15 19:24:09 +02:00
CallbackTransformer.php [Various] Fixed errors on PHPDocs exception names (TransformationFailedException) 2011-08-09 00:14:29 +02:00
CallbackValidator.php fixed CS 2011-06-08 12:16:48 +02:00
composer.json bumped Symfony version to 2.0.6-DEV 2011-11-02 14:18:45 +01:00
DataMapperInterface.php fixed CS 2011-06-08 12:16:48 +02:00
DataTransformerInterface.php [Various] Fixed errors on PHPDocs exception names (TransformationFailedException) 2011-08-09 00:14:29 +02:00
Form.php [Form] added a method to help debugging forms (Form::getAllErrorsAsString()) 2011-09-25 14:33:17 +02:00
FormBuilder.php [Form] Fix for treatment zero as empty data. Closes #1986 2011-08-22 15:19:31 +02:00
FormError.php Better docstring for FormError constructor 2011-07-09 16:14:57 +02:00
FormEvents.php removed the ON_ prefix for Form event names 2011-05-31 07:19:18 +02:00
FormExtensionInterface.php [Form] phpDoc 2011-05-13 11:00:04 +02:00
FormFactory.php Enhance error messages with regard to form type properties. 2011-11-01 14:16:02 +01:00
FormFactoryInterface.php [Various] Fixed phpdoc 2011-05-29 23:33:36 +00:00
FormInterface.php [Form] phpDoc 2011-05-13 11:00:04 +02:00
FormTypeExtensionInterface.php fixed CS 2011-06-08 12:16:48 +02:00
FormTypeGuesserChain.php fixed CS 2011-06-08 12:16:48 +02:00
FormTypeGuesserInterface.php fixed CS 2011-06-08 12:16:48 +02:00
FormTypeInterface.php fixed CS 2011-06-08 12:16:48 +02:00
FormValidatorInterface.php fixed CS 2011-06-08 12:16:48 +02:00
FormView.php [Form] minor code simplification 2011-06-09 13:24:55 -03:00
LICENSE added LICENSE files for the subtree repositories 2011-02-22 18:58:15 +01:00
ReversedTransformer.php [Form] Fix the ReversedTransform class 2011-05-10 20:25:22 +02:00