I want to use sonata media bundle for medias in my bundle.
I have one entity which should have a gallery. After installing sonata media bundle and generating easy:extends, there are 3 diffrent entities:
How can I link these entities to my own entity for gallery implementation???
You can link one-to-one. for example, my implementation:
config.yml:
contexts:
product:
providers:
- sonata.media.provider.image
formats:
big: { width: 1680 , quality: 100}
Gallery.php:
private $product;
Gallery.orm.xml:
<one-to-one field="product" target-entity="Alteza\ProductBundle\Entity\Product" inversed-by="gallery">
<join-column name="product_id" referenced-column-name="id" />
</one-to-one>
Product.php:
/**
* @ORM\OneToOne(targetEntity="\Application\Sonata\MediaBundle\Entity\Gallery", mappedBy="product", cascade={"all"})
*/
private $gallery;
ProductAdmin.php:
->add('gallery', 'sonata_type_model_list', array('required' => false), array('link_parameters' => array('context' => 'product')))
Here is the documentation about the implementation:
http://sonata-project.org/blog/2013/10/11/mediabundle-mediatype-improved
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With