I am refering to a missing feature in Symfony: https://github.com/symfony/symfony/issues/3622
I have several entities that have a OneToOne-relation to an Address
entity. All these OneToOne-relations come alongside the constraint @Valid()
. Consequently, I have an AddressFormType
that is embedded in other forms. Sometimes the addresses in the various forms are required and sometimes they are not.
Problem
Even when I have a validation group defined in the entity Address
, it is not possible to pass this validation group along using the following code:
$builder->add('address', AddressFormType::class, array(
'required' => true,
'validation_groups' => array('required'),
));
Now, until Symfony 3.0.0 adding a cascade_validation
could fix this problem. Unfortunately, cascade_validation
was removed in Symfony 3.0.0 and no solution for the problem at hand was provided.
Possible Work-Around
It is possible to disable the validation for the address
field all together and simply validate it in the controller. However, due to the fact that I am using the FOSUserBundle combined with the PUGXMultiUserBundle, that would be an enormous work-around for such a little problem.
Question
Are there any alternatives to validate the addresses properly?