I am trying to relate SonataMediaBundle to another Entity: Products with a relation ManyToMany.
The schema and relation are well created.
However, when I edit or create a new product, I try to add a button where I can search a media file through the media library and a button to upload a new file.
For a relation OneToMany, this is easily done in Admin\ProductAdmin::configureFormFields by adding:
->add('image', 'sonata_type_model_list', array(
'required' => false
), array(
'link_parameters' => array(
'context' => 'default',
'provider' => 'sonata.media.provider.image'
)
))
So I get the same 3 icons as they already been used in the Gallery of SonataMediaBundle (add from library, upload and delete)
BUT on the relation ManyToMany it isn't possible! Because every time I choose a media, it replaces the previous one. So I can't select multiple media types.
I thought on using the same way as The Gallery (galleryHasMedia)
->add('galleryHasMedias', 'sonata_type_collection', array(
'by_reference' => false
), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
'link_parameters' => array('context' => $context)
))
However, it is really complex. How can I choose or upload multiple media files on another Entity through a ManyToMany Relation?