symfony - Sonata Media Bundle - How to extend FormatThumbnail.php -
the sonata media bundle have thumbnail property on provider in config can specify either
sonata.media.thumbnail.format sonata.media.thumbnail.liip_imagine this fine , sonata.media.thumbnail.format 1 works fine want achieve. problem comes in happens within these files.
in formatthumbnail.php there function called generatepublicurl generate url of media file , name of formatted file. use media id within name or url. if have private files not must able see causes problem easy manipulate id id.
i know public files served stay public if url can guessed user access file. specific reason want try , replace id unique reference bundle uses before create actual formatted files not easy change.
i aware there still risks of leaking out data.
i want change this
public function generatepublicurl(mediaproviderinterface $provider, mediainterface $media, $format) { if ($format == 'reference') { $path = $provider->getreferenceimage($media); } else { $path = sprintf('%s/thumb_%s_%s.%s', $provider->generatepath($media), $media->getid(), $format, $this->getextension($media)); } return $path; } to this
public function generatepublicurl(mediaproviderinterface $provider, mediainterface $media, $format) { if ($format == 'reference') { $path = $provider->getreferenceimage($media); } else { $path = sprintf('%s/thumb_%s_%s.%s', $provider->generatepath($media), $media->getproviderreference(), $format, $this->getextension($media)); } return $path; } how override file bundle picks change?
i have followed steps on sonata's site on how install , set bundle using easy extends bundle. have own application\sonata\mediabundle folder extending original sonata\mediabundle.
for installation related information have through documentation(https://sonata-project.org/bundles/media/master/doc/reference/installation.html)
however tried create own thumbnail folder , creating new formatthumbnail.php follows
<?php namespace application\sonata\mediabundle\thumbnail; use sonata\mediabundle\model\mediainterface; use sonata\mediabundle\provider\mediaproviderinterface; use sonata\mediabundle\thumbnail\formatthumbnail baseformatthumbnail; class formatthumbnail extends baseformatthumbnail { /** * overriding replace id reference * * {@inheritdoc} */ public function generatepublicurl(mediaproviderinterface $provider, mediainterface $media, $format) { if ($format == 'reference') { $path = $provider->getreferenceimage($media); } else { $path = sprintf('%s/thumb_%s_%s.%s', $provider->generatepath($media), $media->getproviderreference(), $format, $this->getextension($media)); } return $path; } } but bundle still generates using id instead of reference. there more specific way achieve extending file , overriding function?
after looking @ few different bundles , after looking in code found physically have parameter set use sonata\mediabundle\thumbnail\formatthumbnail.
the solution override parameter in config aswell.
#as top level classification in app/config/config.yml parameters: sonata.media.thumbnail.format: application\sonata\mediabundle\thumbnail\formatthumbnail this way custom formatthumbnail class injected everywhere used within bundle.
Comments
Post a Comment