i'm using sonatamediabundle , want add gallery of images entity, let's ad. each ad has gallery can have multiple media. i've been following this other answer, , has been pretty useful.
i did already, can add galleries entity , add sort of media gallery, want in backend skip provider selection when media added gallery, , automatically select imageprovider, can create image-only gallery.
class ad { /** * @var int * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ private $id; /** * @var string * * @orm\column(name="title", type="string", length=255,nullable=true) */ private $adtitle; /** * @galleryhasmorethanninemedia * @orm\onetoone(targetentity="application\sonata\mediabundle\entity\gallery",mappedby="ad",cascade={"persist"}) * @orm\joincolumn(name="gallery", referencedcolumnname="id",nullable=true) */ private $gallery; }
and in ad sonata admin class:
protected function configureformfields(formmapper $formmapper) { $formmapper ->add('adtitle') ->add('gallery', 'sonata_type_model_list', array( 'cascade_validation' => true, 'required' => false, ), array( 'edit' => 'inline', 'inline' => 'table', 'sortable' => 'position', 'link_parameters' => array('provider' => 'sonata.media.provider.image'), 'admin_code' => 'sonata.media.admin.gallery', ) ); }
somehow need pass link_parameters
not gallery form, each galleryhasmedia being created, each of new media image of imageprovider , gets validation of provider(the extensions,mime type, thumbnail etc.)
so how form looks like
which opens modal window can add galleryhasmedia gallery.
what want upon adding media, modal choose provider not appear, instead select imageprovider automatically. possible pass link_parameters' => array('provider' => 'sonata.media.provider.youtube')
inside nested form value in admin class?
is possible? have modify in admin class or overwrite other form/class?
added sonatamedia configuration:
sonata_media: # if don't use default namespace configuration #class: # media: myvendor\mediabundle\entity\media # gallery: myvendor\mediabundle\entity\gallery # gallery_has_media: myvendor\mediabundle\entity\galleryhasmedia db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr mandatory choose 1 here default_context: default # need set context contexts: default: # default context mandatory providers: - sonata.media.provider.dailymotion - sonata.media.provider.youtube - sonata.media.provider.image - sonata.media.provider.file - sonata.media.provider.vimeo formats: small: { width: 100 , quality: 70} big: { width: 500 , quality: 70} profile_pics: # default context mandatory providers: - sonata.media.provider.image formats: small: { width: 100 , quality: 70} big: { width: 500 , quality: 70} personal_albums: download: strategy: sonata.media.security.private_strategy mode: http providers: - sonata.media.provider.image - sonata.media.provider.file - sonata.media.provider.private formats: default: { width: 100 , quality: 70} cdn: server: path: %cdn_server_path% # http://media.sonata-project.org/ filesystem: local: directory: %kernel.root_dir%/../web/uploads/media create: true providers: #image: # resizer: false file: service: sonata.media.provider.file resizer: false filesystem: sonata.media.filesystem.local cdn: sonata.media.cdn.server generator: sonata.media.generator.default thumbnail: sonata.media.thumbnail.format allowed_extensions: ['mp4','pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pttx', 'odt', 'odg', 'odp', 'ods', 'odc', 'odf', 'odb', 'csv', 'xml'] allowed_mime_types: ['video/mp4','application/pdf', 'application/x-pdf', 'application/rtf', 'text/html', 'text/rtf', 'text/plain'] buzz: connector: sonata.media.buzz.connector.file_get_contents doctrine: orm: entity_managers: default: mappings: applicationsonatamediabundle: ~ sonatamediabundle: ~
try this.
config.yml here define allowed providers:
sonata_media: #... contexts: #... your_context: providers: - sonata.media.provider.image formats: admin: { width: 55 , height: 55 , quality: 80} small: { width: 75 , quality: 80} medium: { width: 125 , quality: 80} big: { width: 265 , quality: 80}
entity.php
//... /** * @orm\onetoone(targetentity="application\sonata\mediabundle\entity\gallery",cascade={"all"}, orphanremoval=true) * @orm\joincolumn(name="gallery", referencedcolumnname="id") */ private $gallery; //...
entityadmin.php here define custom context allowed providers:
//... class entityadmin extends admin { //... // fields shown on create/edit forms protected function configureformfields(formmapper $formmapper) { //... $formmapper ->add('gallery', 'sonata_type_model_list', array( 'btn_list' => false, 'help' => 'your text', ), array( 'link_parameters' => array( 'context' => 'your_context' )) ); //... } //... }
i hope helps.
these steps:
step 1.
step 2.
step 3.
step 4.
Comments
Post a Comment