donjohn / media-bundle
a simple media bundle inspired by sonata media bundle
Installs: 1 112
Dependents: 0
Suggesters: 1
Security: 0
Stars: 2
Watchers: 4
Forks: 2
Open Issues: 22
Type:symfony-bundle
Requires
- php: >=7.1
- ext-fileinfo: *
- ext-gd: *
- ext-mbstring: *
- doctrine/doctrine-bundle: ^1.6
- symfony/filesystem: ^3.4 || ^4.1
- symfony/form: ^3.4 || ^4.1
- symfony/framework-bundle: ^3.4 || ^4.1
- symfony/security-bundle: ^3.4 || ^4.1
- symfony/templating: ^3.4 || ^4.1
- symfony/twig-bundle: ^3.4 || ^4.1
- symfony/validator: ^3.4 || ^4.1
- twig/twig: ^1.28 || ^2.0
Suggests
- api-platform/core: for the awesome api feature
- liip/imagine-bundle: to get filters feature and more for your images
- oneup/uploader-bundle: for the awesome upload of big files feature
- dev-master
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.9
- 3.3.8
- 3.3.7
- 3.3.5
- 3.3.4
- 3.2.7
- 3.2.6
- 3.2.3
- 3.1.1
- 3.0.6
- 3.0.5
- 2.5.2
- 2.4.3
- 2.3.2
- 2.2.3
- 2.1.1
- 1.5.3
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/express-4.18.2
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/terser-4.8.1
- dev-dependabot/npm_and_yarn/eventsource-1.1.1
- dev-dependabot/npm_and_yarn/url-parse-1.5.10
- dev-dependabot/npm_and_yarn/follow-redirects-1.14.8
- dev-dependabot/npm_and_yarn/ajv-6.12.6
- dev-dependabot/npm_and_yarn/tar-4.4.19
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/dns-packet-1.3.4
- dev-dependabot/npm_and_yarn/browserslist-4.16.6
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/ssri-6.0.2
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/npm_and_yarn/elliptic-6.5.4
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/npm_and_yarn/http-proxy-1.18.1
- dev-dependabot/npm_and_yarn/websocket-extensions-0.1.4
- dev-dependabot/npm_and_yarn/acorn-6.4.1
- dev-dev
This package is auto-updated.
Last update: 2025-03-01 00:11:02 UTC
README
Give credits to Sonata, they inspired this bundle.
Installation
Composer
composer require donjohn/media-bundle
Minimal configuration
Create a new class and extends it with Donjohn\MediaBundle\Media
namespace YourBundle\Entity; use Donjohn\MediaBundle\Model\Media as BaseMedia; /** * @ORM\Table() * @ORM\Entity() */ class YourMedia extends BaseMedia { /** * @var integer * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="IDENTITY") */ protected $id; }
LiipImagineBundle
Add this to your config.yml
liip_imagine: filter_sets: full: quality: 100 thumbnail: quality: 75 filters: auto_rotate: ~ thumbnail: { size: [120, 120], mode: outbound }
See LiipImagineBundle Configuration for liip filters configuration
Optional configuration
Change folder for uploaded files
donjohn_media: upload_folder: /AnotherFolder liip_imagine: resolvers: default: web_path: cache_prefix: AnotherFolder/cache
Restrict uploaded file size
donjohn_media: file_max_size: 500M
Providers
Available providers :
- image
- file
Usage
To insert a media in the twig, use the block with an optional filter name, defined in the liip_imagine.filter_sets section. If you don't provider a filter name, 'reference' filter is default. it will return the original media uploaded with any filter or post processing.
{% media mediaObject, '<filter>' %}
You can also pass class/width/height/alt options to the media rendering:
{% media mediaObject, '<filter>' with {class: 'classwanted class2wanted', alt: 'title', width: '200px', height: '50px'} %}
FormType
An Donjohn\MediaBundle\Form\Type\MediaType is available
$builder->add(<fieldName>, MediaType::class, ['media_class'=> YourEntity::class] );
provider option default value is null. A guesser will try on the fly to detect the best provider fo each file unless you define the option. The default guess is 'file'.
Set 'allow_delete' option to false if you don't want to allow removing media from an entity. It removes the unlink checkbox in the form.
Set 'create_on_update' option to true if you don't want to update the current media when uploading a file but rather create a new media instead. Old one is not removed.
If you want to upload a collection of Medias set multiple to true.
$builder->add(<fieldName>, MediaType::class, ['media_class' => YourEntity::class, 'multiple' => true ] );
OneupUploader
For very large files, the bundle includes the Fine Uploader feature thanks to OneUpUploaderBundle.
$builder->add(<fieldName>, MediaType::class, , ['media_class' => YourEntity::class, 'fine_uploader' => true, 'multiple' => <true|false> ] );
Don't forget to install fineuploader (bower/npm/...) and include the css/js in your layout (fix path if needed).
Add the OneupUploaderBundle to your AppKernel.php
new Oneup\UploaderBundle\OneupUploaderBundle(),
And to config.yml, add:
# Read the documentation: https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md oneup_uploader: chunks: storage: directory: "%kernel.cache_dir%/uploader/chunks" mappings: donjohn_media: namer: Donjohn\MediaBundle\Uploader\Naming\OriginalNamer use_orphanage: true frontend: fineuploader
You can change the uploaded chunk size or the template used to render the fineuploader frame
donjohn_media: chunk_size: 50M #default fine_uploader_template: YourFineUploaderTempalte.twig.html
Custom MediaProvider
To implement your own provider, extends the BaseProvider and redefine abstract function.
Autowiring should do the job...
Api platform
The bundle is compatible with APIPlatform.