Reputation: 5853
I have a simple class constraint validator which is referenced correctly in my entity and I can see that it is being called and returning false when I validate my form based on the entity, but $form->isValid()
is returning true.
Any idea why this is happening? Surely any constraint returning false should cause the form to be invalid?
Entity:
* @ACMEAssert\ExampleConstraint()
ACMEConstraint:
**
* @Annotation
*/
class ExampleConstraint extends Constraint
{
public function validatedBy()
{
return 'acme.example.validator.example';
}
public function getTargets()
{
return Constraint::CLASS_CONSTRAINT;
}
}
ACMEValidator:
class ExampleValidator extends ConstraintValidator
{
public function isValid($entity, Constraint $constraint)
{
return false;
}
}
Upvotes: 1
Views: 333
Reputation: 6529
Try this: Set an error message (Violation):
$this->context->addViolation('bar', array(), null);
Upvotes: 2