Pretty simple with Composer, run:
composer require anime-db/form-type-image-bundle
Add FormTypeImageBundle to your application kernel
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new AnimeDb\Bundle\FormTypeImageBundle\AnimeDbFormTypeImageBundle(),
// ...
);
}
Default config
anime_db_cache_time_keeper:
web_path: '/upload/' # Upload images directory: %kernel.root_dir%/../web/upload/
authorized: true # Only authorized users can upload images
constraint:
files_limit: 10 # Limiting the number of simultaneous file upload
max_size: null # Max file size. Example: 2M
min_width: 0 # Minimum image width
min_height: 0 # Minimum image height
max_width: 0 # Maximum image width
max_height: 0 # Maximum image height
Add form template
twig:
form:
resources: [ 'AnimeDbFormTypeImageBundle:Form:fields.html.twig' ]
Add form templates for SonataDoctrineORMAdminBundle
sonata_doctrine_orm_admin:
templates:
form: [ 'AnimeDbFormTypeImageBundle:Form:sonata_admin_fields.html.twig' ]
use AnimeDb\Bundle\FormTypeImageBundle\Form\Type\ImageType;
use AnimeDb\Bundle\FormTypeImageBundle\Form\Type\ImageCollectionType;
$form = $this
->createFormBuilder()
->add('cover', ImageType::class)
->add('covers', ImageCollectionType::class);