Add those lines to your composer.json
#composer.json
"require": {
...
"awakit/media-bundle": "^3.4"
},
"repositories": [
...
{ "type": "composer", "url": "http://packages.awakit:8000/" }
],
and update
Add thoses bundles to your AppKernel.php
new Liip\ImagineBundle\LiipImagineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Knp\DoctrineBehaviors\Bundle\DoctrineBehaviorsBundle(),
new Awakit\MediaBundle\AwakitMediaBundle(),
Add thoses route to your routing.yml
#app/config/routing.yml
media:
resource: "@AwakitMediaBundle/Resources/config/routing.yml"
Create a new class and extends it with Awakit\MediaBundle\Media
namespace YourBundle\Entity;
use Awakit\MediaBundle\Model\Media as BaseMedia;
/**
* @ORM\Table()
* @ORM\Entity()
*/
class YourMedia extends BaseMedia
{
}
Then add these lines to your config.yml
doctrine:
dbal:
types:
json: Doctrine\DBAL\Types\JsonArrayType
awakit_media:
upload_folder: /media
entities:
YourBundle/Entity/YourMedia: ~
AnotherBundle/Entity/AnotherMedia: ~ #example, AnotherMedia also extends Awakit\MediaBundle\Entity\Media, you can define as much as media class you need
liip_imagine:
filter_sets: #example set, define yours
full:
quality: 100
thumb:
quality: 75
filters:
thumbnail: { size: [120, 90], mode: outbound }
see LiipImagineBundle Configuration for liip filters config
If you want another folder for your uploads, don't forget to modify liip setting as well
awakit_media:
upload_folder: /AnotherFolder
liip_imagine:
resolvers:
default:
web_path:
cache_prefix: AnotherFolder/cache
###Providers For the moment only Image (alias 'image') and File (alias 'file') provider are available.
To insert a media in the twig, use the block with an optionnal 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'} %}
you can also ask for the path directly
{% path media, '<filter>' %}
An Awakit\MediaBundle\Form\Type\MediaType is available. Only 'data_class' option is mandatory. 'provider' option default value is 'file', change it if you wanna create a media with another provider (ex 'image'). In case you're editing a persisted media object, the option is overwritten by $media->getProviderName() value in any case
$builder->add(<fieldName>,MediaType::class, array('provider'=> 'image', 'data_class' => 'YourAppBundle:YourMedia));
This bundle is compatible with DunglasApiBundle and NelmioApiDocBundle. No config is needed. 2 api groups are already defined for input and output serialization (api_input and api_output). If you want to change the groups or add new one. Modify the @Groups annotation in your extended class
namespace YourBundle\Entity;
use Awakit\MediaBundle\Model\Media as BaseMedia;
/**
* @ORM\Table()
* @ORM\Entity()
*/
class YourMedia extends BaseMedia
{
/**
* @ORM\Column(type="string", nullable=false)
* @Groups({"new_group_input","another_group_input","new_group_ouput"})
*/
protected $name;
}
and the in the config.yml, modify the configuration
awakit_media:
...
entities:
YourBundle\Entity\YourMedia:
group_input: ['new_group_input', 'another_group_input']
group_output: ['new_group_ouput']
To implement your own provider, use the ProviderInterface or extends the BaseProvider (easier) then defined it as a service with the tag media.provider (beware, the alias must be the same as YourProvider->getAlias())
app.media.your_type.provider:
class: YouApp\YourBundle\YourProvider
tags:
- { name: media.provider, alias: file }
The MediaType is compatible with dropzone.js , set true to 'dropzone' option. Install it and add the the js and css provided by dropzone install to your layout. Beware you can't use twice MediaType with dropzone option set to true within the same form (blame dropzone, or me, prehaps i'm dumb)
$builder = $this->createFormBuilder();
$builder->add('media', MediaType::class, array( ... ,'dropzone' => true ) );
You can upload more than one files at each time, change option maxFiles in the MediaType. Don't forget : each file sumbit the whole form.
$builder = $this->createFormBuilder();
$builder->add('media', MediaType::class, array( ... ,'dropzone' => true, maxFiles => 50) );