In my form, I have a field with required option set to false, this field is optional.
However, I would like to have a notBlank validation on this field when the field is used:
* message="The name field can't be blank",
$form = $event->getForm();
$formData = $form->getData();
$form = $form->setData($formData);
The best way I can see to achieve this is to use a Callback validator on your entity. As this callback is defined in your entity, it has access to all properties. Through the ExecutionContext you can then set violations as needed.