Skip to content

Embedded forms (symfony 3) #51

@sneakyvv

Description

@sneakyvv

This is only an issue since I've upgraded to symfony 3.2.

I have an ExamType form which has a collection of ExamVersionType forms. These latter contain 2 DatetimeType forms and 1 FileType form.

When adding a file, the ExamVersion (object) is being created, but the file itself is not stored. When I edit the Exam again and replace the file for the ExamVersion, then the file is stored.

I already debugged it quite a while and came to the conclusion that line 56 in Iphp\FileStoreBundle\Form\Type\FileTypeBindSubscriber.php
$obj = $form->getParent()->getData();
is not returning anything. Therefore the file (and delete) field are not being added.
I noticed that when editing an existing ExamVersion, i.e. replacing the (unsaved) file, the object is an empty ExamVersion object. The mapping done on line 60 and following can properly complete and the file (& delete) field are being added to the form.
When I hardcoded set $obj = new ExamVersion() then everything seems to work fine.

I guess this is because it's being used inside a CollectionType. The form without data is being added in the Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener as a new form on line 122

        if ($this->allowAdd) {
            foreach ($data as $name => $value) {
                if (!$form->has($name)) {
                    $form->add($name, $this->type, array_replace(array(
                        'property_path' => '['.$name.']',
                    ), $this->options));
                }
            }
        }

Now, why this form has no data, and how I can fix it... I still have no clue after debugging for over 2 days...

Can someone shed some light on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions