Seems that the addValidator function of the FormBuilder is gone in the recent version of symfony2. Anyonw know how to rewrite that functionality?
Here's my 2.0 code:
$builder-> addValidator(new CallbackValidator(function(FormInterface $form){
$email = $form->get('email')->getData();
if (empty( $email )) {
$form['email']->addError(new FormError("Du måste ange en epostadress för användaren"));
}
}));
I understand that the FormBuilder was replaced by "FormBuilderInterface" in 2.1, but I am still a bit confused as to what steps I need to take to rewrite this functionality.
Since Symfony 2.1 FormValidatorInterface
which is implemented by CallbackValidator
is deprecated, and removed in 2.3.
Upgrade to 2.1 file gives solution:
The interface
FormValidatorInterface
was deprecated and will be removed in Symfony 2.3.If you implemented custom validators using this interface, you can substitute them by event listeners listening to the
FormEvents::POST_BIND
(or any other of the*BIND
events). In case you used theCallbackValidator
class, you should now pass the callback directly toaddEventListener
.