curious-inc/file-upload-form-type-bundle

Helper bundle for mapping Dropzone.js frontend to Symfony FormType using File entity

1.2.8 2019-05-15 12:07 UTC

README

Helper bundle for mapping Dropzone.js frontend to Symfony FormType using File entity

This bundle was heavily inspired by sopinet/UploadFilesBundle.

Installation

Installing prerequisites

Make sure you have Oneup\UploaderBundle installed and configured before you proceed.
See their documentation for setting up this bundle.

Note: Make sure you enable orphanage management by setting the use_orphanage configuration setting to true.

Installing the bundle

Use composer to install the bundle

$ composer require curious-inc/file-upload-form-type-bundle

Registering the bundle in AppKernel

Register both OneUp/Uploader bundle and this bundle in AppKernel

// app/AppKernel.php

$bundles = [

  ...

  new Oneup\UploaderBundle\OneupUploaderBundle(),
  new CuriousInc\FileUploadFormTypeBundle\CuriousIncFileUploadFormTypeBundle(),

  ...

]

Configuring the bundle

Routing configuration

Edit your applications routing configuration

# /app/config/routing.yml

...

# Routing for CuriousInc FileUploadFormType bundle
curious_file_upload:
    resource: '@CuriousIncFileUploadFormTypeBundle/Resources/config/routing.yml'

...
Bundle configuration

Edit your applications configuration file to reflect the following changes

Form configuration

# /app/config/config.yml

...

# Map template to FormType 
twig:
    form_themes:
        - 'CuriousIncFileUploadFormTypeBundle:Form:file.html.twig'

...

Form configuration for SonataAdmin (if applicable)

# /app/config/config.yml

...

# Sonata DoctrineOrmAdmin template overrides
sonata_doctrine_orm_admin:
    templates:
        types:
            list:
                dropzone:  '@CuriousIncFileUploadFormTypeBundle:Admin:file.html.twig'
                ...
            show:
                dropzone:  '@CuriousIncFileUploadFormTypeBundle:Admin:file.html.twig'
                ...

...

OneUp/UploaderBundle configuration

# app/config/config.yml

...

# Configuration for oneup/uploader-bundle
oneup_uploader:
    mappings:
        gallery:
            frontend: 'dropzone'
            use_orphanage: true
            namer: curious_file_upload.file_namer # needed 
            storage:
                directory: '%kernel.project_dir%/web/uploads/gallery'

...