anime-db/form-type-image-bundle

Image upload form type

dev-master 2016-05-25 14:36 UTC

This package is auto-updated.

Last update: 2024-10-15 20:33:56 UTC


README

Latest Stable Version Latest Unstable Version Total Downloads Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight License

Image upload form type

Installation

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(),
        // ...
    );
}

Configuration

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' ]

Usage

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);