I have defined Constraints in my Entity as the documentation said like this example bellow :
/**
* @ORM\Column(type="float", nullable=true)
* @Assert\Type(type={"float", "integer"}, message="Budget have to be a number")
*/
private $budget;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotNull
*/
private $statut;
But when I send invalid value throw the form, the error message that is send is not the one in my constraints entity but the "default one" : "This value is not valid" instead of "Budget have to be a number" in this example.
/**
* @Route("/composition/{id}/edition", name="composition_edition")
*/
public function editionComposition(Composition $composition_edit, Request $request, EntityManagerInterface $manager)
{
$form = $this->createForm(EditionCompositionType::class, $composition_edit);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$manager->persist($composition_edit);
$manager->flush();
return $this->json([
'erreurs' => "ok"
], 200);
}
else
{
$errors = array();
foreach ($form->all() as $child)
{
if (!$child->isValid())
{
$errors[$child->getName()] = (String) $form[$child->getName()]->getErrors();
}
}
return $this->json([
'erreurs' => $errors
], 200);
}
}
Do you know how to have the good error message ?