11How to Dynamically Configure Validation Groups
22==============================================
33
4- Sometimes you need advanced logic to determine the validation groups. If this
4+ Sometimes you need advanced logic to determine the validation groups. If they
55can't be determined by a simple callback, you can use a service. Create a
66service that implements ``__invoke `` which accepts a ``FormInterface `` as a
77parameter.
88
99.. code-block :: php
1010
11+ // src/AppBundle/Validation/ValidationGroupResolver.php
1112 namespace AppBundle\Validation;
1213
1314 use Symfony\Component\Form\FormInterface;
@@ -42,15 +43,15 @@ Then in your form, inject the resolver and set it as the ``validation_groups``.
4243
4344.. code-block :: php
4445
45- use Symfony\Component\OptionsResolver\OptionsResolverInterface;
46- use Symfony\Component\Form\AbstractType
46+ // src/AppBundle/Form/MyClassType.php;
47+ namespace AppBundle\Form;
48+
4749 use AppBundle\Validator\ValidationGroupResolver;
50+ use Symfony\Component\Form\AbstractType
51+ use Symfony\Component\OptionsResolver\OptionsResolver;
4852
4953 class MyClassType extends AbstractType
5054 {
51- /**
52- * @var ValidationGroupResolver
53- */
5455 private $groupResolver;
5556
5657 public function __construct(ValidationGroupResolver $groupResolver)
@@ -59,7 +60,7 @@ Then in your form, inject the resolver and set it as the ``validation_groups``.
5960 }
6061
6162 // ...
62- public function setDefaultOptions(OptionsResolverInterface $resolver)
63+ public function configureOptions(OptionsResolver $resolver)
6364 {
6465 $resolver->setDefaults(array(
6566 'validation_groups' => $this->groupResolver,
0 commit comments