Pre submit data.

@param FormEvent $event
4105
public function preSubmitData(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

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

        foreach ($form as $name => $child) {
            if (!isset($data[$name])) {
                $form->remove($name);
            }
        }
    }
513289
public function preCreate(CreateEvent $event)
    {
        /** @var Group $role */
        $object = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $object->setUser($user);
        } else {
            $object->setUser($this->userManager->getDefaultClarolineUser());
        }
    }
195590
public function onSubmit(FormEvent $event)
    {
        $form = $event->getForm()->getParent();
        $data = $form->getData();

        if (!\is_object($data)) {
            return;
        }

        $accessor = PropertyAccess::createPropertyAccessor();
        $newCollection = $accessor->getValue($data, $this->name);
        if (!$newCollection instanceof Collection) {
            return;
        }
        /* @var $newCollection Collection */

        $newCollection->clear();

        /** @var $item FormBuilder */
        foreach ($form->get($this->name) as $key => $item) {
            if ($item->get('_delete')->getData()) {
                // do not re-add a deleted child
                continue;
            }
            if ($item->getName() && !is_numeric($item->getName())) {
                // keep key in collection
                $newCollection[$item->getName()] = $item->getData();
            } else {
                $newCollection[] = $item->getData();
            }
        }
    }
195576
public function onBefore(BeforeEvent $event)
    {
        $now       = new \DateTime;
        $createdAt = $now->format($this->getDateFormat());
        $request   = $event->getRequest();
        $nonce     = call_user_func($this->getNonce(), $request);
        $password  = $this->passwordProcessor ? call_user_func($this->passwordProcessor, $this->password) : $this->password;
        $digest    = call_user_func($this->getDigest(), $nonce, $createdAt, $password);

        $request->setHeader('Authorization', 'WSSE profile="UsernameToken"');
        $request->setHeader(
            'X-WSSE',
            $this->createWsseHeader(
                $this->username,
                $digest,
                $nonce,
                $createdAt
            )
        );
    }
656857
protected function populatePreviousData(Form $form) {
		$prepops = EventAttendee::config()->prepopulated_fields;
		if (!$prepops) {
			return;
		}
		$latestattendee = $this->registration->Attendees()
			->sort("LastEdited", "DESC")->first();
		if($latestattendee){
			$form->loadDataFrom($latestattendee, Form::MERGE_DEFAULT, $prepops);	
		}
	}
1105328
public function onFormSuccess(FormEvent $event)
    {
        $form = $event->getForm();

        $result = $this->createResult($form);

        if ($form->getStoreResults()) {
            $this->storeResult($form, $result);
        }

        if ($form->getSendMail()) {
            $this->sendMail($form, $result);
        }

        $successUrl = $form->getSuccessUrl();

        if ($successUrl != null) {
            $redirectResponse = new RedirectResponse($successUrl);
            $redirectResponse->send();
        }
    }
224503
public function preSetData(FormEvent $event)
    {
        /** @var SessionConfigurationInterface $configuration */
        $configuration = $event->getData();

        if (empty($configuration) || empty($configuration) && $event->getForm()->has('answers')) {
            return;
        }

        $this->addAnswersFields($event->getForm());
        $this->addFlag($event);
    }
1352632
public function onLayoutBoxFormInit(FormEvent $event)
    {
        $builder       = $event->getFormBuilder();
        $form          = $event->getForm();
        $configurators = $this->container->get('layout_box.configurator.collection')->all();
        $resource      = $event->getResource();
        $boxSettings   = $resource->getSettings();
        
        foreach ($configurators as $configurator) {
            if ($configurator instanceof LayoutBoxConfiguratorInterface) {
                $defaults = [];
                if ($resource->getBoxType() == $configurator->getType()) {
                    $defaults = $boxSettings;
                }
                
                $configurator->addFormFields($builder, $form, $defaults);
            }
        }
    }
127386
public function beforeValidate($event)
    {
        $formName = $event->sender->formName();
        $primaryKey = $event->sender->primaryKey;

        /** @var ActiveRecord $sender */
        $sender = $event->sender;

        /** @var MetaTags $metaTags */
        $metaTags = $sender->{$this->relationName};
        if (!$metaTags) {
            $metaTags = Yii::createObject(MetaTags::class);
            $metaTags->model = $formName;
            $metaTags->model_id = $primaryKey;
            $metaTags->language = $this->lang();
            $metaTags->load(Yii::$app->request->post());
        }

        $sender->populateRelation($this->relationName, $metaTags);
    }
498037
public function preSetData(FormEvent $event)
    {
        $entity = $event->getData();
    
        if ($entity instanceof FileInterface && null !== $entity->getId()){
            try {
                $this->fileManager->copyFileToTemporaryDirectory($entity);
            } catch (\Gaufrette\Exception\FileNotFound $e) {
                $event->setData(null);
            }
        }
    }
727173
public function onPreSetData(FormEvent $event) {
        $item = $event->getData();
        $form = $event->getForm();


        // Meeting is defined -> keep it as hidden field
        if ($item && null != $item->getMeeting()) {
            $form->add('meeting', 'entity_hidden', ["class" => 'Interne\SeanceBundle\Entity\Meeting']);
        }
        // Meeting is not defined -> generate a select
        else {
            $form->add('meeting', 'entity', [
                'class' => 'InterneSeanceBundle:Meeting',
                'choice_label' => 'name',
                'placeholder' => 'Réserve de points...',
                'empty_value' => null,
                'expanded' => true,
                ]);
        }
    }
1144217
public function beforeSave(Event $event)
    {
        if (isset($this->_controller()->request->data['password'])) {
            $password = $this->_controller()->request->data['password'];
            $event->subject->entity['password'] = $password;
        }
    }
230890
public function postSetData(FormEvent $event)
    {
        $collection = $event->getData();
        $form = $event->getForm();
        
        if ($collection instanceof PersistentCollection){
            
            foreach ($collection as $key => $image){
                if ($image instanceof MultiImageInterface && null !== $image->getId()){
                    try{
                        $this->imageManager->copyImagesToTemporaryDirectory($image);
                    } catch(\Gaufrette\Exception\FileNotFound $e){
                        $form->remove($key);
                        $collection->removeElement($image);
                    }
                    
                }
            }
        }
    }
472019
public function beforeRender(Event $event)
    {
        if (!array_key_exists('_serialize', $this->viewVars) &&
            in_array($this->response->type(), ['application/json', 'application/xml'])
        ) {
            $this->set('_serialize', true);
        }
    }
374360
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
                }
            }
        }
    }
1150107
public function preSetData(FormEvent $event)
    {
        $entity = $event->getData();
        $form = $event->getForm();

        $entityConfiguration = $this->getTranslatableEntityConfiguration($entity);

        if (is_null($entityConfiguration)) {
            return null;
        }

        $entityFields = $entityConfiguration['fields'];

        foreach ($entityFields as $fieldName => $fieldConfiguration) {
            if (!$form->has($fieldName)) {
                continue;
            }

            $formConfig = $form
                ->get($fieldName)
                ->getConfig();

            $form
                ->remove($fieldName)
                ->add($fieldName, new TranslatableFieldType(
                    $this->entityTranslationProvider,
                    $formConfig,
                    $entity,
                    $fieldName,
                    $entityConfiguration,
                    $fieldConfiguration,
                    $this->locales,
                    $this->masterLocale,
                    $this->fallback
                ), [
                    'mapped' => false,
                ]);
        }
    }
114756
protected function beforeSave($event)
    {
        if ($this->autoSave) {
            $this->saveFile($this->owner->{$this->uploadAttribute}, $this->name, $this->path);
        }
    }