Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use sonata media bundle with my entities

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:

  • Media.php
  • Gallery.php
  • GalleryHasMedia.php.

How can I link these entities to my own entity for gallery implementation???

like image 996
Karol F Avatar asked Apr 25 '12 18:04

Karol F


2 Answers

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')))
like image 170
Igor Al Avatar answered Oct 19 '22 02:10

Igor Al


Here is the documentation about the implementation:

http://sonata-project.org/blog/2013/10/11/mediabundle-mediatype-improved

like image 24
ivan Avatar answered Oct 19 '22 02:10

ivan