I use Sonata to make an app and I am facing some problem with MediaBundle. I Have two entities :
Product & ProductImage
Inside Product I have this :
/**
* @ORM\ManyToMany(targetEntity="ProductImage", cascade={"persist"}, fetch="LAZY", indexBy="ASC")
*/
protected $medias;
Inside ProductImage :
/**
* @ORM\ManyToOne(targetEntity="Product", cascade={"persist"}, fetch="LAZY")
*/
protected $Product;
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Media\Media", cascade={"persist"}, fetch="LAZY")
*/
protected $image;
public function __toString()
{
global $kernel;
$provider = $kernel->getContainer()->get($this->getImage()->getProviderName());
return $provider->generatePublicUrl($this->getImage(),'small');
}
In my ProductAdmin.php file :
public function configureShowFields(ShowMapper $showMapper)
{
$showMapper
->add('name')
->end()
->with('Medias', array('class' => 'col-md-12'))
->add('medias', 'sonata_type_collection', array(), array(
'inline' => 'table',
'sortable' => 'position'
))
->end();
}
When I go to the show page ( .../product/6/show), I have all my information correctly display but medias is just a list of public URL. How can I display each image instead of URL ?
Thanks