Pre bind

@param FormEvent $event
334075
public function preSubmit(FormEvent $event)
    {
        $data = $event->getData();

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

        if (!empty($data) && isset($data['answers']) && is_string($data['answers'])) {
            $data['answers'] = array($data['answers']);
        }

        $this->addAnswersFields($event->getForm());
        $this->addFlag($event);
    }
76212
public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if (null === $data) {
            throw new \InvalidArgumentException('Can\'t handle null datas.');
        }

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

        foreach ($form as $name => $child) {
            $form->remove($name);
        }

        foreach ($this->schema->getGroups() as $schemaGroup) {
            $form->add($schemaGroup->getName(), new GroupType(), array('label' => $schemaGroup->getTitle()));
            $groupForm = $form->get($schemaGroup->getName());
            foreach ($schemaGroup->getDefinitions() as $schemaDefinition) {
                if (true === $schemaDefinition->getVirtual()) {
                    continue;
                }
                $this->appendProperForm($groupForm, $schemaDefinition);
                $this->appendProperData($data, $schemaDefinition);
            }
        }

        $event->setData($data);
    }
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);
    }
689948
public function onPreSerialize(ObjectEvent $event)
    {
        $configuredType = $event->getObject();

        if ($configuredType instanceof ConfiguredType) {
            try {
                $configurationArray = json_decode($configuredType->getConfiguration(), true);
                $extraFormType = $this->registry->getType($configurationArray['form_type']);
                $configuredType->setExtraFormType($extraFormType);
            } catch (\Exception $e) {
                return;
            }
        }
    }
291428
public function submit(FormEvent $event)
    {
        try{
            $form = $event->getForm();
            $parentForm = $form->getParent();
            $parentData = $parentForm->getData();

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

                $em = $this->doctrineService->getManagerForClass($entityClass);
                $repository = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');

                // Gets the translatable fields and their content
                $translatableFields = $this->getTranslatableFields($entityClass);
                $data = $event->getData();

                foreach ($this->localeList as $locale) {
                    if ($locale != $this->currentLocale) {
                        // Here we extract the field values from the submitted data
                        // Here type is useless, just used for getting the field
                        foreach ($translatableFields as $field => $type) {
                            // Here just translate the data
                            $repository->translate($parentData, $field, $locale, $data[$field."-".$locale] );
                        }
                    }
                }

            }
        } 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;
        }
    }
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);
    }
95885
public function submit(FormEvent $event)
    {
        $entity = $event->getData();
        
        if ($entity instanceof FileInterface && null === $entity->getId() && null === $entity->getHash()){
            $event->setData(null);
        }
    }
271110
public function onPreSubmit(FormEvent $event)
    {
        $contentInfo = null;
        $contentLanguages = [];
        $form = $event->getForm();
        $data = $event->getData();

        if (isset($data['location'])) {
            try {
                $location = $this->locationService->loadLocation($data['location']);
            } catch (NotFoundException $e) {
                $location = null;
            }

            if (null !== $location) {
                $contentInfo = $location->getContentInfo();
                $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
                $contentLanguages = $versionInfo->languageCodes;
            }
        }

        $this->addLanguageFields($form, $contentLanguages, $contentInfo);
    }
598279
public function onPreSubmitData(FormEvent $event)
    {
        $data = $event->getData();
        if (!array_key_exists('site_root', $data) || false === (bool)$data['site_root']) {
            $location = $this->locationService->loadLocation($data['location']);
            if (1 >= $location->depth) {
                return;
            }
            $parentLocation = $this->locationService->loadLocation($location->parentLocationId);
            $urlAlias = $this->urlAliasService->reverseLookup($parentLocation);
            $data['path'] = $urlAlias->path . '/' . $data['path'];
            $event->setData($data);
        }
    }
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);
    }
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);	
		}
	}
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);
        }
    }
922430
public function beforeRender(Event $event)
    {
        parent::beforeRender($event);

        $this->set('detect', $this->detect);
    }
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,
                ]);
        }
    }
898829
public function beforeFilter(Event $event)
    {
        $this->_controller->set('__commentComponentLoaded__', true);
        $this->_controller->set('_commentFormContext', $this->config('arrayContext'));
    }
410632
public function beforeInsert($event)
    {
        $fields = $this->fields;
        $nowDate = gmdate($this->databaseTimeFormat);
        if (!$this->isActuallyDirty()) {
            return;
        }

        if (isset($this->fields['createdField']) && !$this->owner->isAttributeChanged($this->fields['createdField'])) {
            $this->owner->{$this->fields['createdField']} = $nowDate;
        }
        if (isset($this->fields['createdByField']) && !$this->owner->isAttributeChanged($this->fields['createdByField'])) {
            $this->owner->{$this->fields['createdByField']} = self::_getUserId();
        }

        if (isset($this->fields['modifiedField']) && !$this->owner->isAttributeChanged($this->fields['modifiedField'])) {
            $this->owner->{$this->fields['modifiedField']} = $nowDate;
        }
        if (isset($this->fields['modifiedByField']) && !$this->owner->isAttributeChanged($this->fields['modifiedByField'])) {
            $this->owner->{$this->fields['modifiedByField']} = self::_getUserId();
        }
    }
110017
public function preSetData(FormEvent $event)
    {
        $form = $event->getForm();

        $options = $form->getConfig()->getOptions();
        $name    = $form->getName();
        $className = $options['choice_list_class'];
        $method = $options['choice_list_method'];
        $parent = $options['choice_data_chain'];

        $parentForm = $form->getParent()->get($parent);
        $parentOptions = $parentForm->getConfig()->getOptions();

        $baseId = '';
        $ff = clone $form;
        while ($ff->getParent() instanceof FormInterface)
        {
            $ff = $ff->getParent();
            $baseId = $ff->getName() . '_' . $baseId;
        }
        $baseId = trim($baseId, '_');

        $parentId = $baseId . '_'. $parentForm->getName();
        $childId = $baseId . '_'. $name;

        $parentType = $options['parent_type'];
        $list = $className::$method();

        $values = [];
        $choicesAttr = [];

        foreach($list as $optGroup=>$items) {
            foreach ($items as $item) {
                $values[$optGroup][$item['label']] = $item['value'];
                $choicesAttr[$item['value']] = ['data-chained' => $item['data-chained']];
            }
        }

        $options['choices'] = $values;
        $options['choice_attr'] = function($choiceValue, $key, $value) use ($choicesAttr) {
            // adds a class like attending_yes, attending_no, etc
            return $choicesAttr[$choiceValue];
        };
        unset($options['choice_list_class'], $options['choice_list_method'], $options['choice_list_prefix'], $options['choice_data_chain'], $options['parent_type']);

        ScriptManager::addScript('@HillrangeForm/Script/chained_choice.html.twig');
        ScriptManager::addScript('@HillrangeForm/Script/chained_script.html.twig', ['parentId' => $parentId, 'childId' => $childId]);

        $form->getParent()->add($parent, $parentType, $parentOptions);
        $form->getParent()->add($name, ChoiceType::class, $options);
    }