2017 © Pedro Peláez
 

symfony-bundle media-bundle

a simple media bundle inspired by sonata media bundle

image

donjohn/media-bundle

a simple media bundle inspired by sonata media bundle

  • Tuesday, April 3, 2018
  • by Donjohn
  • Repository
  • 2 Watchers
  • 2 Stars
  • 472 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 3 Forks
  • 0 Open issues
  • 43 Versions
  • 2 % Grown

The README.md

SensioLabsInsight, (*1)

Give credits to Sonata, they inspired this bundle., (*2)

Installation

Composer

composer require donjohn/media-bundle

Minimal configuration

Create a new class and extends it with Donjohn\MediaBundle\Media, (*3)

namespace YourBundle\Entity;
use Donjohn\MediaBundle\Model\Media as BaseMedia;

/**
 * @ORM\Table()
 * @ORM\Entity()
 */
class YourMedia extends BaseMedia
{
    /**
     * @var integer
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
    */
    protected $id;
}

LiipImagineBundle

Add this to your config.yml, (*4)

liip_imagine:
    filter_sets:
        full: 
            quality: 100
        thumbnail:
            quality: 75
            filters:
                auto_rotate: ~
                thumbnail: { size: [120, 120], mode: outbound }

See LiipImagineBundle Configuration for liip filters configuration, (*5)

Optional configuration

Change folder for uploaded files, (*6)

donjohn_media:
    upload_folder: /AnotherFolder

liip_imagine:
    resolvers:
        default:
            web_path:
                cache_prefix: AnotherFolder/cache

Restrict uploaded file size, (*7)

donjohn_media:
    file_max_size: 500M

Providers

Available providers : - image - file, (*8)

Usage

To insert a media in the twig, use the block with an optional filter name, defined in the liip_imagine.filter_sets section. If you don't provider a filter name, 'reference' filter is default. it will return the original media uploaded with any filter or post processing., (*9)

{% media mediaObject, '<filter>' %}

You can also pass class/width/height/alt options to the media rendering:, (*10)

{% media mediaObject, '<filter>' with {class: 'classwanted class2wanted', alt: 'title', width: '200px', height: '50px'} %}

FormType

An Donjohn\MediaBundle\Form\Type\MediaType is available, (*11)

$builder->add(<fieldName>, MediaType::class, ['media_class'=> YourEntity::class] );

provider option default value is null. A guesser will try on the fly to detect the best provider fo each file unless you define the option. The default guess is 'file'., (*12)

Set 'allow_delete' option to false if you don't want to allow removing media from an entity. It removes the unlink checkbox in the form., (*13)

Set 'create_on_update' option to true if you don't want to update the current media when uploading a file but rather create a new media instead. Old one is not removed., (*14)

If you want to upload a collection of Medias set multiple to true., (*15)

$builder->add(<fieldName>, MediaType::class, ['media_class' => YourEntity::class, 'multiple' => true ] );

OneupUploader

For very large files, the bundle includes the Fine Uploader feature thanks to OneUpUploaderBundle., (*16)

$builder->add(<fieldName>, MediaType::class, , ['media_class' => YourEntity::class, 'fine_uploader' => true, 'multiple' => <true|false> ] );

Don't forget to install fineuploader (bower/npm/...) and include the css/js in your layout (fix path if needed)., (*17)

Add the OneupUploaderBundle to your AppKernel.php, (*18)

    new Oneup\UploaderBundle\OneupUploaderBundle(),

And to config.yml, add:, (*19)

# Read the documentation: https://github.com/1up-lab/OneupUploaderBundle/blob/master/Resources/doc/index.md
oneup_uploader:
    chunks:
        storage:
            directory: "%kernel.cache_dir%/uploader/chunks"
    mappings:
        donjohn_media:
            namer: Donjohn\MediaBundle\Uploader\Naming\OriginalNamer
            use_orphanage: true
            frontend: fineuploader

You can change the uploaded chunk size or the template used to render the fineuploader frame, (*20)

donjohn_media:
    chunk_size: 50M #default
    fine_uploader_template: YourFineUploaderTempalte.twig.html

Custom MediaProvider

To implement your own provider, extends the BaseProvider and redefine abstract function.
Autowiring should do the job..., (*21)

Api platform

The bundle is compatible with APIPlatform., (*22)

The Versions

09/02 2018