All Projects → silasjoisten → sonata-multiupload-bundle

silasjoisten / sonata-multiupload-bundle

Licence: MIT license
No description or website provided.

Programming Languages

PHP
23972 projects - #3 most used programming language
Twig
543 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects
Makefile
30231 projects

Projects that are alternatives of or similar to sonata-multiupload-bundle

EasyAdminPlusBundle
EasyAdminPlusBundle is a Symfony 4 wrapper for the amazing EasyCorp/EasyAdminBundle
Stars: ✭ 39 (+34.48%)
Mutual labels:  symfony-bundle, symfony4
EasyAuditBundle
A Symfony Bundle To Log Selective Events
Stars: ✭ 84 (+189.66%)
Mutual labels:  symfony-bundle, symfony4
doctrine-json-odm
JSON Object-Document Mapping bundle for Symfony and Doctrine
Stars: ✭ 15 (-48.28%)
Mutual labels:  symfony-bundle, symfony4
Mercure Bundle
The MercureBundle allows to easily push updates to web browsers and other HTTP clients in the Symfony full-stack framework, using the Mercure protocol.
Stars: ✭ 195 (+572.41%)
Mutual labels:  symfony-bundle
Gifexceptionbundle
😛 The GhostBuster of your exception page!
Stars: ✭ 197 (+579.31%)
Mutual labels:  symfony-bundle
Victoire
Fullstack Symfony CMS: The perfect mix between a framework and a CMS
Stars: ✭ 227 (+682.76%)
Mutual labels:  symfony-bundle
Lexikmaintenancebundle
This Symfony2 bundle allows you to place your website in maintenance mode by calling two commands in your console. A page with status code 503 appears to users, it is possible to authorize certain ips addresses stored in your configuration.
Stars: ✭ 253 (+772.41%)
Mutual labels:  symfony-bundle
Webauthn Framework
FIDO-U2F / FIDO2 / Webauthn Framework
Stars: ✭ 182 (+527.59%)
Mutual labels:  symfony-bundle
Enqueue Bundle
[READ-ONLY] Message queue bundle for Symfony. RabbitMQ, Amazon SQS, Redis, Service bus, Async events, RPC over MQ and a lot more
Stars: ✭ 233 (+703.45%)
Mutual labels:  symfony-bundle
Schedule Bundle
Schedule Cron jobs (commands/callbacks/bash scripts) within your Symfony application.
Stars: ✭ 216 (+644.83%)
Mutual labels:  symfony-bundle
Sonataintlbundle
Symfony SonataIntlBundle
Stars: ✭ 212 (+631.03%)
Mutual labels:  symfony-bundle
Rich Model Forms Bundle
Provides additional data mappers that ease the use of the Symfony Form component with rich models.
Stars: ✭ 198 (+582.76%)
Mutual labels:  symfony-bundle
Alicedatafixtures
Nelmio Alice extension to persist the loaded fixtures.
Stars: ✭ 228 (+686.21%)
Mutual labels:  symfony-bundle
Alice
Expressive fixtures generator
Stars: ✭ 2,289 (+7793.1%)
Mutual labels:  symfony-bundle
Fosrestbundle
This Bundle provides various tools to rapidly develop RESTful API's with Symfony
Stars: ✭ 2,683 (+9151.72%)
Mutual labels:  symfony-bundle
Breadcrumbsbundle
A small breadcrumbs bundle for Symfony
Stars: ✭ 190 (+555.17%)
Mutual labels:  symfony-bundle
Easyadminextensionbundle
Provides some additional features to EasyAdminBundle for Symfony
Stars: ✭ 232 (+700%)
Mutual labels:  symfony-bundle
Monolog Bundle
Symfony Monolog Bundle
Stars: ✭ 2,532 (+8631.03%)
Mutual labels:  symfony-bundle
Liiphellobundle
[DEPRECATED] Alternative Hello World Bundle for Symfony2 using several FriendsOfSymfony Bundles
Stars: ✭ 206 (+610.34%)
Mutual labels:  symfony-bundle
Auditor Bundle
Doctrine audits logs made easy.
Stars: ✭ 221 (+662.07%)
Mutual labels:  symfony-bundle

silasjoisten/sonata-multiupload-bundle

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

Versions

Sample

Checkout the Sample Project

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

You have to open the configuration file for this bundle and configure the providers which you want to enable multi upload.

# config/packages/sonata_multi_upload.yaml

sonata_multi_upload:
  # ...
  providers:
    - sonata.media.provider.image
    - sonata.media.provider.video

Add JavaScript and CSS to SonataAdmin config:

# 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

# config/packages/sonata_multi_upload.yaml

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

There is an option redirect_to which allows you to redirect after complete upload to your configured page.

# config/packages/sonata_multi_upload.yaml

sonata_multi_upload:
  redirect_to: 'admin_sonata_media_media_list'

HINT: The MultiUploadBundle passes automatically the id's from the uploaded Media objects to the redirection route for example: /foo/bar?idx=%5B70%2C71%2C72%5D so you can take them and create a gallery from uploaded medias.

Example: Uploading multiple images and create automatically a Gallery

Create controller

The controller takes your request and create in this example a Gallery with GalleryItems and redirects to the edit view of GalleryAdmin

<?php

namespace App\Controller;

use App\Entity\SonataMediaGallery;
use App\Entity\SonataMediaGalleryItem;
use Sonata\MediaBundle\Admin\GalleryAdmin;
use Sonata\MediaBundle\Entity\MediaManager;
use Sonata\MediaBundle\Entity\GalleryManager;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

final class CreateGalleryAction
{
    public function __construct(
        private MediaManager   $mediaManager,
        private GalleryManager $galleryManager,
        private GalleryAdmin   $galleryAdmin
    ) {
    }

    public function __invoke(Request $request): RedirectResponse
    {
        $idx = $request->query->get('idx');
        $idx = json_decode($idx);

        /** @var SonataMediaGallery $gallery */
        $gallery = $this->galleryManager->create();
        $gallery->setName('Auto Created Gallery');
        $gallery->setEnabled(false);
        $gallery->setContext('default');

        foreach ($idx as $id) {
            $media = $this->mediaManager->find($id);

            $galleryHasMedia = new SonataMediaGalleryItem();
            $galleryHasMedia->setGallery($gallery);
            $galleryHasMedia->setMedia($media);
            $gallery->addGalleryItem($galleryHasMedia);
        }

        $this->galleryManager->save($gallery);

        return new RedirectResponse($this->galleryAdmin->generateObjectUrl('edit', $gallery));
    }
}

Register route

If you already override the default MediaAdmin you can add the route in the admin class via

   protected function configureRoutes(RouteCollectionInterface $collection): void
    {
        $collection->add('create_gallery', 'multi-upload/create-gallery', [
            '_controller' => CreateGalleryAction::class,
        ]);
    }

otherwise you can create an AdminExtension like the following:

<?php

declare(strict_types=1);

namespace App\Admin\Extension;

use App\Controller\CreateGalleryAction;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Route\RouteCollectionInterface;

final class MediaAddRouteExtension extends AbstractAdminExtension
{
    public function configureRoutes(AdminInterface $admin, RouteCollectionInterface $collection): void
    {
        $collection->add('create_gallery', 'multi-upload/create-gallery', [
            '_controller' => CreateGalleryAction::class,
        ]);
    }
}

and register this extension in your config/services.yaml

services:
    # ...
    App\Admin\Extension\MediaAddRouteExtension:
        tags:
            - { name: sonata.admin.extension, target: sonata.media.admin.media }

Now configure the redirect_to in config/packages/sonata_multi_upload.yaml

sonata_multi_upload:
    redirect_to: 'admin_app_sonatamediamedia_create_gallery'

Maybe you need to create an alias for MediaManager and GalleryManager like:

# config/services.yaml
services:
  Sonata\MediaBundle\Entity\MediaManager:
    alias: sonata.media.manager.media

  Sonata\MediaBundle\Entity\GalleryManager:
    alias: sonata.media.manager.gallery

  Sonata\MediaBundle\Admin\GalleryAdmin:
    alias: sonata.media.admin.gallery

Thats it.

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

4. Look & Feel

multiupload

Used Library:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].