public function onSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if (null === $data) {
            $data = array();
        }

        if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        // The data mapper only adds, but does not remove items, so do this here
        $toDelete = array();

        foreach ($data as $name => $child) {
            if (null === $child || (
                $form->get($name)->has('__to_remove') &&
                true === $form->get($name)->get('__to_remove')->getData()
            )) {
                $toDelete[] = $name;
            }
        }

        foreach ($toDelete as $name) {
            unset($data[$name]);
        }

        if ($data instanceof \Doctrine\Common\Collections\Collection) {
            $event->setData($data->getValues());
        } else {
            $event->setData($data);
        }
    }
public function onSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if (null === $data) {
            $data = array();
        }

        if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        // The data mapper only adds, but does not remove items, so do this here
        $toDelete = array();

        foreach ($data as $name => $child) {
            if (null === $child || (
                $form->get($name)->has('__to_remove') &&
                true === $form->get($name)->get('__to_remove')->getData()
            )) {
                $toDelete[] = $name;
            }
        }

        foreach ($toDelete as $name) {
            unset($data[$name]);
        }

        if ($data instanceof \Doctrine\Common\Collections\Collection) {
            $event->setData($data->getValues());
        } else {
            $event->setData($data);
        }
    }
public function onSubmit ( FormEvent $ event ) { $ form = $ event -> getForm ( ) ; $ data = $ event -> getData ( ) ; if ( null === $ data ) { $ data = array ( ) ; } if ( ! is_array ( $ data ) && ! ( $ data instanceof \ Traversable && $ data instanceof \ ArrayAccess ) ) { throw new UnexpectedTypeException ( $ data , 'array or (\Traversable and \ArrayAccess)' ) ; } // The data mapper only adds, but does not remove items, so do this here $ toDelete = array ( ) ; foreach ( $ data as $ name => $ child ) { if ( null === $ child || ( $ form -> get ( $ name ) -> has ( '__to_remove' ) && true === $ form -> get ( $ name ) -> get ( '__to_remove' ) -> getData ( ) ) ) { $ toDelete [ ] = $ name ; } } foreach ( $ toDelete as $ name ) { unset ( $ data [ $ name ] ) ; } if ( $ data instanceof \ Doctrine \ Common \ Collections \ Collection ) { $ event -> setData ( $ data -> getValues ( ) ) ; } else { $ event -> setData ( $ data ) ; } }
On submit.

@param FormEvent $event
On submit .