Search code examples
phpsymfonysonata-adminsonata

Preview image in sonata media bundle in configureFormFields


How make preview image in media fields in sonata admin bundle ?

This-> https://symfony.com/doc/master/bundles/SonataAdminBundle/cookbook/recipe_image_previews.html no working Return

Attempted to call an undefined method named "getWebPath" of class ...


Solution

  • you must implement a getWebPath method in your entity Image class (look at pre-requisites), something like:

    protected function getUploadDir()
    {
        return '/uploads';
    }
    
    public function getWebPath()
    {
        return null === $this->path
            ? 'null'
            : $this->getUploadDir().'/'.$this->path;
    }