Pre set data.

@param FormEvent $event
193012
public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();

        foreach ($form as $name => $child) {
            $form->remove($name);
        }
    }
807060
public function postSubmit(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect the submitted data of each form
            $this->dataCollector->collectSubmittedData($event->getForm());

            // Assemble a form tree
            // This is done again after the view is built, but we need it here as the view is not always created.
            $this->dataCollector->buildPreliminaryFormTree($event->getForm());
        }
    }
114756
protected function beforeSave($event)
    {
        if ($this->autoSave) {
            $this->saveFile($this->owner->{$this->uploadAttribute}, $this->name, $this->path);
        }
    }
862885
public function preSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $formHash = $this->getFormHash($form);
        $this->submittedDataPlain[$formHash] = $event->getData();
    }
989639
public function onPreSerialize(PreSerializeEvent $event)
    {
        $object = $event->getObject();
        if ($object instanceof ExtRefHoldingDocumentInterface && $object->isEmptyExtRefObject() === true) {
            $event->setType('Empty', [$object]);
        }
    }
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
            )
        );
    }
1321695
public function onPreSetData(FormEvent $event)
    {
        if (!$event->getData() || !$event->getForm()->getConfig()->getOption('removable')) {
            return;
        }

        $event->getForm()->add('remove', 'checkbox', array(
            'label' => $this->options['remove_label']
        ));
    }
657916
public function onSubmit(FormEvent $event)
    {
        $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)');
        }

        foreach ($this->schema->getGroups() as $schemaGroup) {
            foreach ($schemaGroup->getDefinitions() as $schemaDefinition) {
                if (true === $schemaDefinition->getVirtual()) {
                    continue;
                }
                $identifier = $schemaDefinition->getIdentifier();
                if ($data->offsetExists($identifier)) {
                    /** @var CharacteristicInterface $characteristic */
                    $characteristic = $data->offsetGet($identifier);
                    if ($this->isNullOrEqualsParentData($characteristic)) {
                        $data->offsetUnset($identifier);
                        $this->em->remove($characteristic);
                    } else {
                        $characteristic->setIdentifier($identifier);
                    }
                } else {
                    throw new \RuntimeException(sprintf('Missing [%s] characteristic data.', $identifier));
                }
            }
        }

        $event->setData($data);
    }
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);
            }
        }
    }
589407
public function preSetData(FormEvent $event)
    {
        try{
            $form = $event->getForm();
            $parentForm = $form->getParent();
            $parentData = $parentForm->getData();

            // First, we get the entity class
            $entityClass = get_class($parentData);

            // Then, we get the field list from the entity class metadata using the annotation reader
            $translatableFields = $this->getTranslatableFields($entityClass);

            //Case where there is data (edit);
            if ($parentData && method_exists($parentData, 'getId') && $parentData->getId()) {

                // We get the entity manager and its translations
                $em = $this->doctrineService->getManagerForClass($entityClass);
                
                if (!$em) {
                    $em = $this->doctrineService->getManager('default');
                }

                $repository = $em->getRepository($this->translation_class);
                $translations = $repository->findTranslations($parentData);

                // Iterating over the enabled locales
                foreach ($this->localeList as $locale) {
                    // Case of the default locale : do not display the form
                    if ($locale != $this->currentLocale) {

                        // We first add the fields without translation
                        $this->addTranslationlessFieldsForLocale($translatableFields, $parentForm, $form, $locale);

                        // If the locale has its translation
                        if (isset ($translations[$locale])) {
                            // then we get its data per field
                            // this way if a field has a translation it will automatically be filled
                            foreach($translations[$locale] as $field => $translation) {
                                if ($parentForm->has($field)) {
                                    // Here we have to first retrieve the field type in the parent form
                                    $fieldType = $parentForm->get($field)->getConfig()->getType()->getInnerType();
                                    // and then set the form type and the data
                                    $fieldAttr = $parentForm->get($field)->getConfig()->getOption('attr');
                                    $form->add(sprintf("%s-%s", $field, $locale), $fieldType, array('data' => $translation, 'required' => false, 'attr' => array_merge($fieldAttr, array('data-field-name' => $field, 'data-locale' => $locale))));
                                }
                            }
                        }
                    }
                }

                // end of the process
                return;
            }

            // Here case where there is an entity but empty one.
            $this->addTranslationlessFields($translatableFields, $parentForm, $form);

        } catch (\Exception $e) {
            // Case of a non entity object given to the parent form.
            // Unstranslatable case, throw exception
            $secondException = new \Exception("The object that was given to the form you wanted to translate isn't an entity one. Untranslatable in this case.", $e->getCode(), $e);
            throw $secondException;
        }
    }
694086
public function createForm(FormEvent $event): void
    {
        $admin = $event->getAdmin();
        $action = $admin->getAction();
        $configuration = $action->getConfiguration();

        if (!$configuration->get('use_form')) {
            return;
        }
        $entity = null;

        if (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $configuration->get('load_strategy')) {
            if (!$admin->getEntities()->isEmpty()) {
                $entity = $admin->getEntities()->first();
            }
        }

        if ('create' === $action->getName() || 'edit' === $action->getName()) {
            $form = $this->adminFormFactory->createEntityForm($admin, $event->getRequest(), $entity);
            $event->addForm($form, 'entity');
        }

        if ('delete' === $action->getName()) {
            $form = $this->adminFormFactory->createDeleteForm($action, $event->getRequest(), $entity);
            $event->addForm($form, 'delete');
        }
    }
391935
public function preSubmit(FormEvent $event): void
    {
        $rawData = $event->getData();
        $form = $event->getForm();
        $data = $form->getData();

        Assert::isInstanceOf($data, CustomerInterface::class);

        // if email is not filled in, go on
        if (!isset($rawData['email']) || empty($rawData['email'])) {
            return;
        }

        /** @var CustomerInterface|null $existingCustomer */
        $existingCustomer = $this->customerRepository->findOneBy(['email' => $rawData['email']]);
        if (null === $existingCustomer || null !== $existingCustomer->getUser()) {
            return;
        }

        $existingCustomer->setUser($data->getUser());
        $form->setData($existingCustomer);
    }
628453
public static function normalize(FormEvent $event)
    {
        $data = $event->getData();
        $data = array_merge(
            [
                'mainWebspace' => self::getAndUnsetValue($data['structure'], 'mainWebspace'),
                'additionalWebspaces' => self::getAndUnsetValue($data['structure'], 'additionalWebspaces'),
            ],
            $data
        );

        $event->setData($data);
    }
1366640
public function beforeRender(Event $event)
    {
        $this->set('authUser', $this->authUser);
        $this->set('title', $this->name);

        $event = new Event('CakeAdmin.Controller.beforeRender', $this);
        EventManager::instance()->dispatch($event);
    }
70780
public function preSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $form->getData();

        if (is_array($event->getData())) {
            $order = array_flip(array_keys($event->getData()));
            if (is_null($data)) {
                $data = array();
            }

            if ($data instanceof Collection) {
                $dataClone = $data->toArray();
                $data->clear();
                foreach ($order as $key => $value) {
                    $data->set($key, array_key_exists($key, $dataClone) ? $dataClone[$key] : null);
                }
            } elseif (is_array($data)) {
                $oldData = array_merge(array(), $data);
                $data = array();
                foreach ($order as $key => $value) {
                    $data[$key] = array_key_exists($key, $oldData) ? $oldData[$key] : null;
                }

            }
            $form->setData($data);
        }
    }
1289697
public function onPreSetData(FormEvent $event)
    {
        $form = $event->getForm();
        if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
            $roles = [
                'User' => 'ROLE_USER',
                'Admin' => 'ROLE_ADMIN',
                'Super admin' => 'ROLE_SUPER_ADMIN',
            ];
            $form
                ->add(
                    'roles',
                    ChoiceType::class,
                    [
                        'label' => 'Roles',
                        'required' => true,
                        'expanded' => true,
                        'multiple' => true,
                        'choices' => $roles,
                    ]
                );
        }
    }
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
                }
            }
        }
    }