Symfony 2 get Sonata media file path in Entity class Symfony 2 get Sonata media file path in Entity class symfony symfony

Symfony 2 get Sonata media file path in Entity class


I don't think it is possible without giving the Entity class to much responsibilities since you can't tell the absolute path name without having some services ('sonata.media.manager.media', 'sonata.media.provider.image' or 'sonata.media.twig.extension')..

The proper way to go is to build a clone function into an controller. The controller can have all the magic (services and entitymanagers) to do the cloning for you.

See this stackoverflow question for an example.