我想删除表单集合中的某些实体,具体取决于其他提交的值。这是我在Symfony 2.5中的最小代码,但它不再适用于Symfony 3
public function buildForm(FormBuilderInterface $builder, array $options)
{
$myformentity = $options['data'];
$builder
->add('mycollection', CollectionType::class)
->add('mycheckbox',CheckboxType::class, array(
'required'=> false,
'mapped' => false,
));
$builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use($myformentity) {
$form = $event->getForm();
if($form->get('mycheckbox')->getData()){
// Remove some entities in $myformentity->mycollection
}
});
}
问题在于,即使正确删除了实体并且在删除后正确执行了验证,仍会验证已删除的entites并且表单提交失败。
我该怎么办?