Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3920

Sonata Admin CollectionType to add one-to-many entities

$
0
0

I'm using Sonata Admin Bundle 3.4 with Symfony 4.3.

I'm trying to figure out how to add multiple somethings to an entity. For the sake of this example, it could be GalleryHasMedias to a Gallery, as mentioned in the documentation: https://sonata-project.org/bundles/doctrine-orm-admin/3-x/doc/reference/form_field_definition.html#advanced-usage-one-to-many

My first issue was that I didn't get a select-box to select existing GalleryHasMedias. I just got the label. This was resolved by adding 'allow_add' => true to the options array, but now I just get a plain input field for each added row.

What I would like instead, is a select-box with the existing GalleryHasMedias plus an 'Add new' button, so that I can create a new one. When creating a new one, I would expect a form in a modal where I could enter the details about my new GalleryHasMedia.

I've set up the Gallery entity with OneToMany GalleryHasMedias, and my GalleryAdmin looks like this:

        $formMapper
            ->add(
                'galleryHasMedias',
                CollectionType::class,
                [
                    'by_reference' => false,
                    'allow_add' => true,
                ],
                [
                    'edit' => 'inline',
                    'inline' => 'table',
                    'sortable' => 'position',
                    'limit' => 3,
                ]
        );

What else do I need to set this up?


Viewing all articles
Browse latest Browse all 3920

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>