->add('regions', null, [
'choices' => isset($this->entity) ? $this->entity->getRegions() : [] ,
'required' => false
])
->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
$data = $event->getData();
$form = $event->getForm();
if(!empty($data['regions'])) {
$regionsCollection = new ArrayCollection();
foreach($data['regions'] as $region) {
$regionsCollection->add($this->em->getRepository('AppBundle:Region')->find($region));
}
$form->add('regions', null, [
'data' => $regionsCollection
]);
}
});