title: Sonata Media Bundle remove gallery
body: <p>I have the Sonata Media Bundle installed but I don't use the gallery portion of the bundle. </p>
  
  <p>How do I disable the Gallery?</p>
  
  <p>I am using Symfony 2.3 and I have the standard Media Bundle install as per the documentation.</p>
  
  <h2>Solution thus far:</h2>
  
  <p>If you look at this issue <a href="https://github.com/sonata-project/SonataAdminBundle/issues/460" rel="nofollow">https://github.com/sonata-project/SonataAdminBundle/issues/460</a> from the admin bundle you can disable a admin by adding the <code>show_in_dashboard: false</code> tag to the yaml file.</p>
  
  <p>To do this I simply add my own compiler that adds this flag for me then:</p>
  
  <ol>
  <li><p>Create your compiler: <a href="http://symfony.com/doc/current/components/dependency_injection/tags.html" rel="nofollow">http://symfony.com/doc/current/components/dependency_injection/tags.html</a></p></li>
  <li><p>Add your compiler to your bundle: <a href="http://symfony.com/doc/2.3/cookbook/service_container/compiler_passes.html" rel="nofollow">http://symfony.com/doc/2.3/cookbook/service_container/compiler_passes.html</a></p></li>
  </ol>
  
  <p>And you are done. If there is a better solution I'd love to hear about it.</p>
  
  <p>Example of compiler: </p>
  
  <pre><code>namespace YourBundle\DependencyInjection\Compiler;
  
  use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  use Symfony\Component\DependencyInjection\ContainerBuilder;
  
  class OverrideMediaGalleryCompilerPass implements CompilerPassInterface
  {
  
      /**
       * You can modify the container here before it is dumped to PHP code.
       *
       * @param ContainerBuilder $container
       *
       * @api
       */
      public function process( ContainerBuilder $container )
      {
          $definition = $container-&gt;getDefinition( 'sonata.media.admin.gallery' );
          if ( $definition ) {
              /**
               * The purpose here is to disable the sonata admin gallery from showing up
               * in the dashboard. This goes through and adds show_in_dashboard parameter
               * that disables this.
               */
              if ( $definition-&gt;hasTag( 'sonata.admin' ) ) {
                  $tags                             = $definition-&gt;getTag( 'sonata.admin' );
                  $tags[ 0 ][ 'show_in_dashboard' ] = false;
                  $definition-&gt;clearTag( 'sonata.admin' );
                  $definition-&gt;addTag( 'sonata.admin', $tags[ 0 ] );
              }
          }
      }
  }
  </code></pre>