To keep the field level constraints at a central place (not replicate it in each form), I added the constraints in the entity. Like below (lets say its one of the fields of a user entity):
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255, nullable=false)
*
* @Constraints\NotBlank(
* groups={"register", "edit"},
* message="email cannot be blank."
* )
* @Constraints\Email(
* groups={"register", "edit"},
* message="Please enter a valid email address."
* )
*
* @Expose
* @Groups({"list", "details"})
*/
private $email;
Now I need a way to expose this validation constraints for each field which is an annotation of "Symfony\Component\Validator\Constraints". Is there a way that I can get all the constraints for all fields in the entity, like:
$em->getValidationConstraints('MyBundle:EntityUser'); //em is the entity manager
//and it returns me all the fields with its name, type and any constraints
//attached to it as any array
Thanks in advance.