I am looking for a way to implement multiple data-transformers for one entity.
I am adding forms in a FormType like this:
//RegistrationFormType.php
...
$sectionsForm = $factory->createNamed('sections', 'form', null, array(
'label' => false,
'auto_initialize' => false
));
foreach ($sections as $key=>$section) {
$sectionform = $factory->createNamed('section_'.$section->getId(),'form', null, array(
'label' => $section->getName(),
));
$formQuestions = $section->getFormQuestions();
foreach ($formQuestions as $formQuestion) {
$sectionform->add('question_'.$formQuestion->getId(), 'text',array('attr'=>...));
...
}
$sectionsForm->add($sectionform);
}
$form->add($sectionsForm);
$builder->addModelTransformer(new RegistrationFormToArrayTransformer($em));
Now in the ModelTransformer, I am transforming the RegistrationForm entity like this:
$sections['section_'.$sectionId]['question_'.$questionId] = ...
Is there a more elegant way to do this? My source code is getting quite messy and was wondering if I can somehow have multiple array-transformers, one for each entity.