1
votes

I'm using sonata admin and mediabundle in symfony 3.2 application.

composer.json

"sonata-project/admin-bundle": "3.x-dev",
"sonata-project/doctrine-orm-admin-bundle": "4.x-dev",
"sonata-project/media-bundle": "4.x-dev",
"sonata-project/intl-bundle": "2.x-dev"

I generate mediabundle as said in doc

sf3 sonata:easy-extends:generate --dest=src SonataMediaBundle

Then in my entity I add a relation with media entity:

   /**
     * @ORM\OneToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"})
     * @ORM\JoinColumn(name="image_id", referencedColumnName="id", onDelete="SET NULL")
     */
    protected $image;

I configure sonata media as said in doc:

sonata_media:
    db_driver: doctrine_orm
    default_context: default
    contexts:
        default:
            providers:
                - sonata.media.provider.image
                - sonata.media.provider.file
            formats:
                small: { width: 100 , quality: 70}
                big:   { width: 500 , quality: 70}
    filesystem:
        local:
            directory:  "%kernel.root_dir%/../web/uploads/media"
    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/

and then added it to my admin

->add('logo', 'sonata_type_model_list', array('required' => false), array(
                    'link_parameters' => ['provider'=>'sonata.media.provider.image'],
                    'label'    => 'Logo',
                    'context'  => 'default',
                    'required' => false,
                ))

When i try to add an image i get this error:

You have requested a non-existent service "request". Did you mean one of these: "data_collector.request", "monolog.logger.request", "request_stack", "router.request_context", "sonata.intl.locale_detector.request_stack", "validate_request_listener"?

So i try to understand where it use $this->container->get('request') but i find out that in sonata code it use something like:

if ($this->container->has('request_stack')) {
            return $this->container->get('request_stack')->getCurrentRequest();
        }


return $this->container->get('request');

That seems to be right. So why i get this error?

2
Using development versions is not recommended at all, why are you doing that?greg0ire
Because when i create the project symfony 3.2 is also in dev and i've got a lot of problem with dependencies.Isky
If symfony 3.2 is also in dev, don't use it. The dev version is not meant for you, it's meant for people who want to contribute a bc-breaking change to the next version.greg0ire
I use symfony 3.2 because it will be release in November. By the way i solve the issue changing the version of sonata in my composer but it need some change to work with symfony3. Thanks for suggestion.Isky
Consider reporting the issues you have with sf3 compatibility, or even contributing some fixesgreg0ire

2 Answers

0
votes

I write this answer to people who don't want to use sonata classification bundle with sonata media bundle (like me) so have to use 4.x-dev. I make a commit to make it compatible with symfony3 (seems). Hope this help.

-1
votes

The request service no longer exists with Symfony3.

You must use the request_stack service instead