public function preSubmit(FormEvent $event)
    {
        $data = $event->getData();
        $entity = $event->getForm()->getParent()->getConfig()->getDataClass();

        //if the remove checkbox is checked, clear the data
        if (isset($data[FileType::REMOVE_FIELDNAME]) &&  $data[FileType::REMOVE_FIELDNAME] === '1') {
            $event->setData(null);
            $data = null;
            return;
        }

        if (null !== ($file = $this->getUploadedFile($data))) {
            $this->validateFile($file, $event);
        } else {
            // nothing uploaded
            $hash = $data[FileType::HASH_FIELDNAME];
            $filename = $data[FileType::FILENAME_FIELDNAME];

            // check if there was a purgatory file (and the file is not tampered with)
            if (!empty($hash) && !empty($filename)
                && PurgatoryHelper::makeHash($event->getForm()->getPropertyPath(), $filename) === $hash
            ) {
                $path = $this->getPurgatoryFileManager()->getFilePath(
                    $entity,
                    $this->field,
                    $filename
                );

                $this->prepareData($data, $path, $event->getForm()->getPropertyPath());
                $event->setData($data);

                //use the original form data, so the field isn't empty
            } elseif ($event->getForm()->getData() !== null) {

                unset($data[FileType::HASH_FIELDNAME]);
                unset($data[FileType::FILENAME_FIELDNAME]);

                $originalFormData = $event->getForm()->getData();
                $path = $this->fileManager->getFilePath($entity, $this->field, $originalFormData);

                try {
                    $file = new File($path);
                    $data[FileType::UPLOAD_FIELDNAME] = $file;
                    $event->setData($data);
                } catch (FileNotFoundException $e) {
                    //do nothing
                }
            }
        }
    }
public function preSubmit(FormEvent $event)
    {
        $data = $event->getData();
        $entity = $event->getForm()->getParent()->getConfig()->getDataClass();

        //if the remove checkbox is checked, clear the data
        if (isset($data[FileType::REMOVE_FIELDNAME]) &&  $data[FileType::REMOVE_FIELDNAME] === '1') {
            $event->setData(null);
            $data = null;
            return;
        }

        if (null !== ($file = $this->getUploadedFile($data))) {
            $this->validateFile($file, $event);
        } else {
            // nothing uploaded
            $hash = $data[FileType::HASH_FIELDNAME];
            $filename = $data[FileType::FILENAME_FIELDNAME];

            // check if there was a purgatory file (and the file is not tampered with)
            if (!empty($hash) && !empty($filename)
                && PurgatoryHelper::makeHash($event->getForm()->getPropertyPath(), $filename) === $hash
            ) {
                $path = $this->getPurgatoryFileManager()->getFilePath(
                    $entity,
                    $this->field,
                    $filename
                );

                $this->prepareData($data, $path, $event->getForm()->getPropertyPath());
                $event->setData($data);

                //use the original form data, so the field isn't empty
            } elseif ($event->getForm()->getData() !== null) {

                unset($data[FileType::HASH_FIELDNAME]);
                unset($data[FileType::FILENAME_FIELDNAME]);

                $originalFormData = $event->getForm()->getData();
                $path = $this->fileManager->getFilePath($entity, $this->field, $originalFormData);

                try {
                    $file = new File($path);
                    $data[FileType::UPLOAD_FIELDNAME] = $file;
                    $event->setData($data);
                } catch (FileNotFoundException $e) {
                    //do nothing
                }
            }
        }
    }
public function preSubmit ( FormEvent $ event ) { $ data = $ event -> getData ( ) ; $ entity = $ event -> getForm ( ) -> getParent ( ) -> getConfig ( ) -> getDataClass ( ) ; //if the remove checkbox is checked, clear the data if ( isset ( $ data [ FileType :: REMOVE_FIELDNAME ] ) && $ data [ FileType :: REMOVE_FIELDNAME ] === '1' ) { $ event -> setData ( null ) ; $ data = null ; return ; } if ( null !== ( $ file = $ this -> getUploadedFile ( $ data ) ) ) { $ this -> validateFile ( $ file , $ event ) ; } else { // nothing uploaded $ hash = $ data [ FileType :: HASH_FIELDNAME ] ; $ filename = $ data [ FileType :: FILENAME_FIELDNAME ] ; // check if there was a purgatory file (and the file is not tampered with) if ( ! empty ( $ hash ) && ! empty ( $ filename ) && PurgatoryHelper :: makeHash ( $ event -> getForm ( ) -> getPropertyPath ( ) , $ filename ) === $ hash ) { $ path = $ this -> getPurgatoryFileManager ( ) -> getFilePath ( $ entity , $ this -> field , $ filename ) ; $ this -> prepareData ( $ data , $ path , $ event -> getForm ( ) -> getPropertyPath ( ) ) ; $ event -> setData ( $ data ) ; //use the original form data, so the field isn't empty } elseif ( $ event -> getForm ( ) -> getData ( ) !== null ) { unset ( $ data [ FileType :: HASH_FIELDNAME ] ) ; unset ( $ data [ FileType :: FILENAME_FIELDNAME ] ) ; $ originalFormData = $ event -> getForm ( ) -> getData ( ) ; $ path = $ this -> fileManager -> getFilePath ( $ entity , $ this -> field , $ originalFormData ) ; try { $ file = new File ( $ path ) ; $ data [ FileType :: UPLOAD_FIELDNAME ] = $ file ; $ event -> setData ( $ data ) ; } catch ( FileNotFoundException $ e ) { //do nothing } } } }
Just before the form is submitted, check if there is no data entered and if so, set the 'old' data back.

@param FormEvent $event
@return void
Just before the form is submitted check if there is no data entered and if so set the old data back .