a2lix / AutoFormBundle

Automate Symfony form building
https://a2lix.fr/bundles/auto-form
MIT License
83 stars 30 forks source link

AutoFormType doesn't support Embedded properties #17

Open welcoMattic opened 5 years ago

welcoMattic commented 5 years ago

Hi, thanks a lot for this bundle and TranslationFormBundle, it helps me in many projects !

So, I have a little bit complex context. I work with EasyAdminBundle:

I have a VideoBlock class, translatable (and a VideoBlockTranslation class). In VideoBlock class I have a $videoMedia property, which is declared as follow:

/**
 * @ORM\Embedded(class="App\Entity\CatalogMedia")
 */
private $videoMedia;

CatalogMedia extract:

/**
 * @ORM\Embeddable()
 */
class CatalogMedia
{
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $filename;

    private $file;

// ...

It works like a charm, but now I would like to be able to upload a video for each language. Basically, move $videoMedia in VideoBlockTranslation. Well, here is the problem. If I do this, I can't make my form works. The form is configured like this:

// ... EasyAdmin entity config
            form:
                fields:
                    - { type: 'group', css_class: 'col-md-6', icon: 'gear', label: 'Configuration' }
                    - { property: 'name', label: 'Nom' }

                    - { type: 'group', css_class: 'col-md-6', icon: 'image', label: 'Media' }
                    - { property: 'videoMedia', label: 'Vidéo', type: 'App\Form\CatalogMediaType' }

                    - { type: 'group', css_class: 'col-md-12', icon: 'flag', label: 'Traductions' }
                    - property: 'translations'
                      type: 'A2lix\TranslationFormBundle\Form\Type\TranslationsType'
                      type_options:
                          label: false
                          fields:
                              title: { label: 'titre' }
                              content: { label: 'paragraphe' }

If I move videoMedia, under translations...fields, Symfony tells me that it can't find videoMedia property in VideoBlockTranslation class :thinking:

May be I missed something, but I think that the problem is under AutoFormBundle and about Embedded properties.

Thanks for helping

StephenBeirlaen commented 4 years ago

I have the same issue. The field validation logic uses the list of fields that Doctrine has mapped. Any extra fields will be marked as invalid. Might look at this later, for now I have little time to look further into this, I can stay at version 2 for now.