@@ -526,6 +526,7 @@ to an array callback::
526526
527527 use Symfony\Component\OptionsResolver\OptionsResolverInterface;
528528
529+ // ...
529530 public function setDefaultOptions(OptionsResolverInterface $resolver)
530531 {
531532 $resolver->setDefaults(array(
@@ -541,23 +542,51 @@ This will call the static method ``determineValidationGroups()`` on the
541542The Form object is passed as an argument to that method (see next example).
542543You can also define whole logic inline by using a ``Closure ``::
543544
545+ use Acme\AcmeBundle\Entity\Client;
544546 use Symfony\Component\Form\FormInterface;
545547 use Symfony\Component\OptionsResolver\OptionsResolverInterface;
546548
549+ // ...
547550 public function setDefaultOptions(OptionsResolverInterface $resolver)
548551 {
549552 $resolver->setDefaults(array(
550553 'validation_groups' => function(FormInterface $form) {
551554 $data = $form->getData();
552- if (Entity\ Client::TYPE_PERSON == $data->getType()) {
555+ if (Client::TYPE_PERSON == $data->getType()) {
553556 return array('person');
554- } else {
555- return array('company');
556557 }
558+
559+ return array('company');
560+ },
561+ ));
562+ }
563+
564+ Using the ``validation_groups `` option overrides the default validation
565+ group which is being used. If you want to validate the default constraints
566+ of the entity as well you have to adjust the option as follows::
567+
568+ use Acme\AcmeBundle\Entity\Client;
569+ use Symfony\Component\Form\FormInterface;
570+ use Symfony\Component\OptionsResolver\OptionsResolverInterface;
571+
572+ // ...
573+ public function setDefaultOptions(OptionsResolverInterface $resolver)
574+ {
575+ $resolver->setDefaults(array(
576+ 'validation_groups' => function(FormInterface $form) {
577+ $data = $form->getData();
578+ if (Client::TYPE_PERSON == $data->getType()) {
579+ return array('Default', 'person');
580+ }
581+
582+ return array('Default', 'company');
557583 },
558584 ));
559585 }
560586
587+ You can find more information about how the validation groups and the default constraints
588+ work in the book section about :ref: `validation groups <book-validation-validation-groups >`.
589+
561590.. index ::
562591 single: Forms; Validation groups based on clicked button
563592
0 commit comments