I need to integrate this two bundles to be able to add Tags to an Media Entity (Image, Video, etc.).
I'm using:
"sonata-project/media-bundle":"version": "2.3.1" "sonata-project/classification-bundle":"version": "2.2.1" "symfony/symfony":"version": "v2.4.10"
In the sonata sandbox they demonstrate overriding entities.
I'd suggest reviewing their appbundle directory structure and configs. You may have to use the current 2.3 branch folder layout but the concept is the same.
the examples below will assume you are overriding/extending every entity. If you are only planning on overriding the media entity then I believe you would just need to change the namespace for the
AppBundle\Entity\Classification\TagtoSonata\ClassificationBundle\Model\Tag(not tested)you could add extra properties to the media entity located here
AppBundle\Entity\Media\Media.php
then edit the doctrine xml located here to include these new relationships
AppBundle\Resources\config\doctrine\Media.Media.orm.xml
notice we're creating a new join table called
media__media_tagthis is following the existing patter and prefixing the table withmedia__andmedia_tagindicates the relationship.we have solved the part of extending the current schema. You'll then need to tell the bundle to use your class instead as seen here (this could be in your
app/config/config.ymlinstead of being imported fromapp/config/sonata/sonata_media.ymllike the sandboxThe last step would be to add the property to the MediaAdmin class for management. This part is a little more tricky and I'm not sure if its the most ideal solution.
MediaBundle has an admin class for each storage model
ORM|ODM|PHPCRimplementing the abstract class BaseMediaAdmin unfortunately we would have to extend each one used. I beleive ORM is the most common so we'll extend that onewhat we are looking to do is add a form field for the tags
so creating a new directory
AdmininsideAppBundleand a class calledMediaAdmin(or whatever you like as long as it ends in Admin) and extend the classSonata\MediaBundle\Admin\ORM\MediaAdmin. The example below we override configureFormFields and call the parent before adding the field for tags.AppBundle\Admin\MediaAdmin.php
then we need to add a compiler pass to override the MediaAdmin service with our class.
AppBundle\AppBundle.php
AppBundle\DependencyInjection\Compiler\OverrideServiceCompilerPass.php
if you wanted to add a tag filter you could override
configureDatagridFilters, but this should be everything needed to get you started.