Reorder the children of the parent form data at $this->name.

For whatever reason we have to go through the parent object, just
getting the collection from the form event and reordering it does
not update the stored order.

@param FormEvent $event
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();
            }
        }
    }
509461
public function postSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        if (!$form->isValid()) {
            return;
        }

        $entity = $event->getData();
        $formHash = $this->getFormHash($form);
        $entityConfiguration = $this->getTranslatableEntityConfiguration($entity);

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

        $this->translationsBackup[$formHash] = [];

        $entityData = [
            'object' => $entity,
            'idGetter' => $entityConfiguration['idGetter'],
            'alias' => $entityConfiguration['alias'],
            'fields' => [],
        ];

        $entityFields = $entityConfiguration['fields'];

        foreach ($entityFields as $fieldName => $fieldConfiguration) {
            if (!isset($this->submittedDataPlain[$formHash][$fieldName])) {
                continue;
            }

            $field = $this->submittedDataPlain[$formHash][$fieldName];

            foreach ($this->locales as $locale) {
                $entityData['fields'][$fieldName][$locale] = $field[$locale . '_' . $fieldName];
            }

            if ($this->masterLocale && isset($field[$this->masterLocale . '_' . $fieldName])) {
                $masterLocaleData = $field[$this->masterLocale . '_' . $fieldName];
                $setter = $fieldConfiguration['setter'];
                $entity->$setter($masterLocaleData);
            }
        }

        $this->translationsBackup[$formHash][] = $entityData;
    }
869184
public function submit(FormEvent $event)
    {
        $image = $event->getData();

        if ($image && $image->isNew() && !$image->hasFile()) {
            $event->setData(null);
        }
    }
1030164
public function postSetData(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect basic information about each form
            $this->dataCollector->collectConfiguration($event->getForm());

            // Collect the default data
            $this->dataCollector->collectDefaultData($event->getForm());
        }
    }
137392
public function onPreSetData(FormEvent $event)
    {
        $form = $event->getForm();
        $item = $event->getData();

        foreach ($this->fields as $field) {
            list ($name, $type, $options) = $field;
            if (null !== $item) {
                $options = array_replace($options, $this->itemHelper->getFormOptions($item, $name));
            }
            $form->add($name, $type, $options);
        }
    }
186469
public function validateForm(FormEvent $event)
    {
        $form = $event->getForm();

        if ($form->isRoot()) {
            // Form groups are validated internally (FormValidator). Here we don't set groups as they are retrieved into the validator.
            foreach ($this->validator->validate($form) as $violation) {
                // Allow the "invalid" constraint to be put onto
                // non-synchronized forms
                // ConstraintViolation::getConstraint() must not expect to provide a constraint as long as Symfony\Component\Validator\ExecutionContext exists (before 3.0)
                $allowNonSynchronized = (null === $violation->getConstraint() || $violation->getConstraint() instanceof Form) && Form::NOT_SYNCHRONIZED_ERROR === $violation->getCode();

                $this->violationMapper->mapViolation($violation, $form, $allowNonSynchronized);
            }
        }
    }
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;
        }
    }
944759
public function processCreateDraft(FormActionEvent $event)
    {
        /** @var $createContentDraft \EzSystems\RepositoryForms\Data\Content\CreateContentDraftData */
        $createContentDraft = $event->getData();

        $contentInfo = $this->contentService->loadContentInfo($createContentDraft->contentId);
        $versionInfo = $this->contentService->loadVersionInfo($contentInfo, $createContentDraft->fromVersionNo);
        $contentDraft = $this->contentService->createContentDraft($contentInfo, $versionInfo);
        $referrerLocation = $event->getOption('referrerLocation');

        $event->setPayload('content', $contentDraft);
        $event->setPayload('is_new', $contentDraft->contentInfo->isDraft());

        $contentEditUrl = $this->router->generate('ez_content_draft_edit', [
            'contentId' => $contentDraft->id,
            'versionNo' => $contentDraft->getVersionInfo()->versionNo,
            'language' => $contentDraft->contentInfo->mainLanguageCode,
            'locationId' => null !== $referrerLocation ? $referrerLocation->id : null,
        ]);
        $event->setResponse(new RedirectResponse($contentEditUrl));
    }
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());
        }
    }
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,
                ]);
        }
    }
535493
public function handleForm(FormEvent $event): void
    {
        $admin = $event->getAdmin();
        $action = $admin->getAction();

        if ('delete' === $action->getName()) {
            if (!$admin->hasForm('delete')) {
                return;
            }
            $form = $admin->getForm('delete');
            $this->handleDeleteForm($event->getRequest(), $form, $admin);
        }
    }
471448
public function saveOrder(OrderOnCreatedEvent $event)
    {
        $order = $event->getOrder();

        $this->orderObjectManager->persist($order);
        $this->orderObjectManager->flush($order);
    }
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);
    }
150055
public static function reorderTabs(FormMapper $formMapper, array $tabOrder)
    {
        $tabsOriginal = $formMapper->getAdmin()->getFormTabs();

        //filter out tabs that doesn't exist (yet)
        $tabOrder = array_filter(
            $tabOrder,
            function ($key) use ($tabsOriginal) {
                return array_key_exists($key, $tabsOriginal);
            }
        );

        $tabs = array_merge(array_flip($tabOrder), $tabsOriginal);
        $formMapper->getAdmin()->setFormTabs($tabs);
    }
459803
public function postSetData(FormEvent $e)
    {
        if ($e->getData() === null) {
            return;
        }

        // Checks if the form has a given property
        // A property can be removed in a child class but the eventSubscriber still exists
        if (!$e->getForm()->has($this->property)) {
            return;
        }
        if ($this->provider->supports($e->getData())) {
            if ($item = $this->mm->getItemBy(array(':path' => $this->provider->url($e->getData())))) {
                $item->setAddToMenu(true);
                $e->getForm()->get($this->property)->setData($item);
            }
        }
    }
738574
public function handleReorder(ReorderEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof PageBehavior) {
            return;
        }

        $propertyName = $this->propertyEncoder->systemName(static::FIELD);
        $parentNode = $this->documentInspector->getNode($document->getParent());

        $page = 1;
        foreach ($parentNode->getNodes() as $childNode) {
            $child = $this->documentManager->find($childNode->getIdentifier(), $event->getLocale());
            if (!$child instanceof PageBehavior) {
                continue;
            }

            $childNode->setProperty($propertyName, ++$page);
            $child->setPageNumber($page);
        }
    }
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);
    }