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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -