There is an entity myEntity with the records property of the json type, which after deserialization looks like this:
class myEntity { public function getRecords() { return [ ['param1' => 'value1', 'param2' => 'value2'], ['param1' => 'value1', 'param2' => 'value2'], ]; } } I want to create a form that will be filled with these deserialized values, and leave another “string” for new values:
MAIN FORM -> Record #1 -> Param 1 -> Param 2 -> Record #2 -> Param 1 -> Param 2 -> New Record <- пустая строка для новых значений -> Param 1 -> Param 2 I create a new form in the controller:
$this->container->get('form.factory')->create(myMainForm::class, $myEntity); In the main form I create nested records :
class myMainFormType extends EasyAdminFormType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('records', myRecordsType::class); } } And here I have problems, I don’t know how I can iterate over all existing values of the array (and add one more extra), $ builder-> getData () is empty:
class myRecordsType extends EasyAdminFormType { public function buildForm(FormBuilderInterface $builder, array $options) { // TODO buildForm(), something like: // foreach (... as ...) // { // $builder->add('record', myRecordType::class); // } } } And in the end, the text fields themselves will be created, then everything is clear:
class myRecordType extends EasyAdminFormType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('param1', TextType::class); $builder->add('param2', TextType::class); } }