How to use a sonata package with my entities

I want to use the media sonata package in my kit.

I have one entity that must have a gallery. After installing the sonata package and creating simple: extensions, there are 3 different objects:

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

How to connect these objects with my own entity for the implementation of the gallery?

+5
source share
2 answers
+3
source

You can connect with each other. 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')))
+4
source

All Articles