Sonata media bundle how to enable pixlr editing?

201 Views Asked by At

I have enabled pixlr as described here but is not enabled have tried many times. There is no edit with pixlr button visible in media form.

Am I missing anything, Struggling from long time. Please help, Is there any additional config apart from this?

Here is my config

sonata_media:
    pixlr:
        enabled:  true
        secret:   theSecretHash
        referrer: Demo

    # if you don't use default namespace configuration
    class:
        media: App\Application\Sonata\MediaBundle\Entity\Media
        gallery: App\Application\Sonata\MediaBundle\Entity\Gallery
        gallery_has_media: App\Application\Sonata\MediaBundle\Entity\GalleryHasMedia
        category: App\Application\Sonata\ClassificationBundle\Entity\Category

    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
    default_context: default # you need to set a context
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
                - sonata.media.provider.vimeo

            formats:
                small: { width: 100 , quality: 70 }
                big:   { width: 500 , quality: 70 }            
        gallery: 
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
                - sonata.media.provider.vimeo
            formats:
                original: { width: 500, quality: 100 }
                thumbnail: { width: 200, height: 200, quality: 100 }

    cdn:
        server:
            path: http://127.0.0.1:8000/uploads/media # http://media.sonata-project.org/

    filesystem:
        local:
            directory:  "%kernel.root_dir%/../public/uploads/media" #flex
            #directory:  "%kernel.root_dir%/../web/uploads/media" #non-flex
            create:     false
1

There are 1 best solutions below

0
Sumeet On

After digging into the code I found the problem is with Symfony 4 making services private by default.

And this is how sonata media bundle enables pixlr

First it checks if sonata.media.extra.pixlr service is available in the container. If not then it doesn't enable the pixlr. Since the service is private container is not able to access the service.

// Sonata\MediaBundle\Twig\GlobalVariable

/**
 * @return Pixlr|bool
 */
public function getPixlr()
{
    return $this->container->has('sonata.media.extra.pixlr') ? $this->container->get('sonata.media.extra.pixlr') : false;
}

Workaround for this is to override service definition and make it public :)

sonata.media.extra.pixlr:
    public: true
    class: Sonata\MediaBundle\Extra\Pixlr
    arguments: [~,~,"@sonata.media.pool", "@sonata.media.manager.media", "@router", "@sonata.templating", "@service_container"]

Now you can see pixlr edit button enabled in media form