public function buildForm(FormBuilderInterface $builder, array $options)
{
$defaultRequired = false;
$constraints = array();
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$form = $event->getForm();
$data = $event->getData();
$defaultRequired = false;
$constraints = array();
$fieldType = null;
if (!is_null($data)) {
$fieldType = $data->getFieldType();
$patch = !is_null($this) ? !$this->patch : false;
if ($data->isRequired() && $patch) {
$defaultRequired = true;
$constraints = array(new NotBlank());
}
}
$form->add('data', $fieldType, array('required' => $defaultRequired, 'constraints' => $constraints));
});
}