silasjoisten/sonata-multiupload-bundle

A Bundle which allows you to enable Multiupload in Sonata

Installs: 1 742

Dependents: 0

Suggesters: 0

Stars: 11

Watchers: 3

Forks: 3

Open Issues: 3

Type:symfony-bundle

2.2.1 2018-09-10 14:19 UTC

README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License codecov

Installation

Step 1: Download the Bundle

$ composer require silasjoisten/sonata-multiupload-bundle

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new SilasJoisten\Sonata\MultiUploadBundle\SonataMultiUploadBundle(),
        );

        // ...
    }

    // ...
}

If you are using flex register bundle in config/bundles.php:

<?php

return [
    //...
    SilasJoisten\Sonata\MultiUploadBundle\SonataMultiUploadBundle::class => ['all' => true]
];

Step 3: Configuration

First you need to override the default MediaAdminController.php set following in your config/services.yaml

parameters:
    sonata.media.admin.media.controller: SilasJoisten\Sonata\MultiUploadBundle\Controller\MultiUploadController

services:
    #...

Now add to the service definition of your Provider and add to tag multi_upload: true like:

App\Provider\VideoProvider:
    arguments:
        - "App\Provider\VideoProvider"
        # ...
    calls:
        # ...
    tags:
        - { name: sonata.media.provider, multi_upload: true }

If you are using default Sonata MediaProvider these arguments are already injected. Otherwise be aware that the provider gets allowedMimeTypes and allowedExtensions injected. This arguments will be used by JavaScript to validate MimeType and FileExtensions before the Request starts.

For Example:

App\Provider\VideoProvider:
    arguments:
        #- "App\Provider\VideoProvider"
        #- "@sonata.media.filesystem.local"
        #- "@sonata.media.cdn.server"
        #- "@sonata.media.generator.default"
        #- "@sonata.media.video.thumbnail"
        - ['mp4', 'mov', 'flv', 'wmv', 'mxf', 'mkv','m4v','mpg']
        - ['video/mp4', 'video/quicktime', 'video/x-flv','video/x-ms-wmv','application/mxf','video/x-matroska','video/x-m4v','video/mpeg']
        # ...

In your provider where you want to use multiupload you need to add following trait: SilasJoisten\Sonata\MultiUploadBundle\Traits\MultiUploadTrait

After That you need to add the dependency to your config/packages/sonata_admin.yaml:

sonata_admin:
    assets:
        extra_stylesheets:
            - bundles/sonatamultiupload/dist/sonata-multiupload.css

        extra_javascripts:
            - bundles/sonatamultiupload/dist/sonata-multiupload.js

OPTIONAL

Create config/packages/sonata_multi_upload.yaml. You can configure following:

sonata_multi_upload:
    max_upload_filesize: 3000000 # 3MB the default value is 0 -> allow every size

Thats it!

Notice that the uploader won't work for Providers like: YouTubeProvider, VimeoProvider!

4. Look & Feel

multiupload

Used Library: