/**
  * {@inheritdoc}
  */
 public function getPersistentParameters()
 {
     $parameters = parent::getPersistentParameters();
     if (!$this->hasRequest()) {
         return $parameters;
     }
     $filter = $this->getRequest()->get('filter');
     if ($filter && array_key_exists('context', $this->getRequest()->get('filter'))) {
         $context = $filter['context']['value'];
     } else {
         $context = $this->getRequest()->get('context', $this->pool->getDefaultContext());
     }
     $providers = $this->pool->getProvidersByContext($context);
     $provider = $this->getRequest()->get('provider');
     // if the context has only one provider, set it into the request
     // so the intermediate provider selection is skipped
     if (count($providers) == 1 && null === $provider) {
         $provider = array_shift($providers)->getName();
         $this->getRequest()->query->set('provider', $provider);
     }
     $categoryId = $this->getRequest()->get('category');
     if (!$categoryId) {
         $categoryId = $this->categoryManager->getRootCategory($context)->getId();
     }
     return array_merge($parameters, array('context' => $context, 'category' => $categoryId, 'hide_context' => (bool) $this->getRequest()->get('hide_context')));
 }
 /**
  * {@inheritdoc}
  */
 public function getPersistentParameters()
 {
     $parameters = parent::getPersistentParameters();
     if (!$this->hasRequest()) {
         return $parameters;
     }
     return array_merge($parameters, array('context' => $this->getRequest()->get('context', $this->pool->getDefaultContext())));
 }
 /**
  * {@inheritdoc}
  */
 protected function configureFormFields(FormMapper $formMapper)
 {
     // define group zoning
     $formMapper->with('Gallery', array('class' => 'col-md-9'))->end()->with('Options', array('class' => 'col-md-3'))->end();
     $context = $this->getPersistentParameter('context');
     if (!$context) {
         $context = $this->pool->getDefaultContext();
     }
     $formats = array();
     foreach ((array) $this->pool->getFormatNamesByContext($context) as $name => $options) {
         $formats[$name] = $name;
     }
     $contexts = array();
     foreach ((array) $this->pool->getContexts() as $contextItem => $format) {
         $contexts[$contextItem] = $contextItem;
     }
     $formMapper->with('Options')->add('context', 'choice', array('choices' => $contexts, 'translation_domain' => 'SonataMediaBundle'))->add('enabled', null, array('required' => false))->add('name')->add('defaultFormat', 'choice', array('choices' => $formats))->end()->with('Gallery')->add('galleryHasMedias', 'sonata_type_collection', array('cascade_validation' => true), array('edit' => 'inline', 'inline' => 'table', 'sortable' => 'position', 'link_parameters' => array('context' => $context), 'admin_code' => 'sonata.media.admin.gallery_has_media'))->end();
 }