forms - symfony choice type should accept array of models -
i cannot find correct way pass array of 'models' choice type. expects 'norm' data, might code duplication many cases imho.
duplicates code of model transformer
$vehicles = $repo->findall(); $vehiclechoice = $builder ->create('vehicle', 'choice', [ 'choices' => \array_map( function(vehicle $v) { return $v->getid(); // same vehiclemodeltransformer::transform }, $vehicles), ]) ->addmodeltransformer( new vehiclemodeltransformer($this->em) ) ;
vs.
form should use model transformer initialize norm data
$vehiclechoice = $builder ->create('vehicle', 'choice', [ 'choices_as_model' => $repo->findall(), // ]) ->addmodeltransformer( new vehiclemodeltransformer($this->em) ) ;
anyone knows how write second way, or convert array of models norm data? in symfony components modeltonorm
private method. code not reusable.
thank you!
as see has own datatransformer make purpose. think better solution case create custom form type vehiclechoice extend built-in choice type , contain required logic.
Comments
Post a Comment