My User entity has few properties:
private $id;
/**
Assert\Email
*/
private $email;
/**
* @Assert\Length( min=6, minMessage="Password is too short (min 6 symbols)" )
*/
private $password;
I'm trying to create a Form for changing password:
createFormBuilder(null, ??? data-class=UserEntity ??? )
->add('YES_CHANGE_PASS',CheckboxType::class,['required'=>false])
->add('old_password',PasswordType::class,['required'=>false])
->add('new_password', RepeatedType::class,['required'=>false])
Problem: if I set the 'data-class=UserEntity::class' to this Form, it stops working (of course, because my Entity doesn't have OLD_PASSWORD\NEW_PASSWORD property). If I don't set 'data-class', the Form obviously won't inherit any constraints (like password @Assert\Length(min=6) constraint)
Solution#1 I dont like: hardcode all the needed constraints right in the createFormBuilder function. I dont like this way because if one day I want to change the Password minLength, I'll have to run through the whole project searching for such forms to edit this
Solution#2 madness: add all the extra fields to my Entity, so it will let me use the 'data-class:UserEntity'... and constraints...and validate... but it's obviously a sick solution
Any hints, please?