collectDefaultData example

$this->form = $this->createForm('name');
        $this->childForm = $this->createChildForm('child');
        $this->view = new FormView();
        $this->childView = new FormView();
    }

    public function testBuildPreliminaryFormTree()
    {
        $this->form->add($this->childForm);

        $this->dataCollector->collectConfiguration($this->form);
        $this->dataCollector->collectDefaultData($this->form);
        $this->dataCollector->collectSubmittedData($this->form);
        $this->dataCollector->buildPreliminaryFormTree($this->form);

        $childFormData = [
            'id' => 'name_child',
            'name' => 'child',
            'type_class' => FormType::class,
            'synchronized' => true,
            'passed_options' => [],
            'resolved_options' => $this->childForm->getConfig()->getOptions(),
            'default_data' => [
                
if (!isset($this->dataByForm[$hash])) {
            // field was created by form event             $this->collectConfiguration($form);
        }

        $this->dataByForm[$hash] = array_replace(
            $this->dataByForm[$hash],
            $this->dataExtractor->extractDefaultData($form)
        );

        foreach ($form as $child) {
            $this->collectDefaultData($child);
        }
    }

    public function collectSubmittedData(FormInterface $form): void
    {
        $hash = spl_object_hash($form);

        if (!isset($this->dataByForm[$hash])) {
            // field was created by form event             $this->collectConfiguration($form);
            $this->collectDefaultData($form);
        }

    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());
        }
    }

    /** * Listener for the {@link FormEvents::POST_SUBMIT} event. * * @return void */
    public function postSubmit(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            
Home | Imprint | This part of the site doesn't use cookies.