phpsonata-adminsonatasymfony-3.3sonata-media-bundle

How to limit SonataMediaBundle gallery to a single provider?


An existing project on which I am working uses SonataMediaBundle. I like the Gallery option provided by that bundle, with one caveat: The gallery allows users to include not just images, but also media from three video providers (YouTube, Vimeo and DailyMotion).

How can I make the bundle only allow images as gallery media?

So far, I have tried searching GalleryAdmin.php for any reference to provider names, but I have yet to find anything obvious in there.

Edit: I also realize that I could just remove the providers I don't want from the sonata.yaml file (and/or sonata_media.yml depending on setup), but that would entirely remove them from the application, which is not quite what I want. I still want to be able to use the YouTube provider, for instance -- just not when creating image galleries.


Solution

  • After doing a bit of research, I came up with a workaround that isn't perfect but does the job. I added the following block to sonata_media.yml:

    galleries:
        providers:
            - sonata.media.provider.image
    
        formats:
            abstract: { width: 100, quality: 100 }
            wide:     { width: 820, quality: 100 }
    

    ... which is not ideal, since it adds a step to the workflow. (I now have to tell clients "If you want to make a gallery, choose the 'galleries' context and then do xyz." It's a bit cluttered, but it reduces the likelihood of unpredictable results.)