Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded forms (symfony 3) #51

Open
sneakyvv opened this issue May 11, 2017 · 1 comment
Open

Embedded forms (symfony 3) #51

sneakyvv opened this issue May 11, 2017 · 1 comment

Comments

@sneakyvv
Copy link

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?

sneakyvv pushed a commit to sneakyvv/IphpFileStoreBundle that referenced this issue May 11, 2017
@sneakyvv
Copy link
Author

sneakyvv commented May 11, 2017

Pull request #52 created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant