I'm trying to create an object of type, say, Slot related to an object of other type, Customer. Here is how the post request body looks like.
{
"name: "foo
"customer": {id: 21}
}
here is how I get the data and build the form:
$data = json_decode($request->getContent(), true);
$entity = new Slot();
$entityManager = $this->getDoctrine()->getManager();
$form = $this->createForm(SlotType::class, $entity);
$form->submit($data, true);
zer
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('customer', EntityType::class, [
"class" => Customer::class
]);
The form I use to submit this data uses an EntityType form type, but it seems it can't recognize the data posted for the customer field and tells me that the value is not valid for this field. Do I need to preprocess the data in the controller to populate my entity with associated entities? Or is there a way to attach dataTransformers to the SlotType to populate the form with valid data ?
You can use a DTO with properties (slotTypeName and customerId), the form will be easier and after the validation you use this DTO to build your entities