PHPackages                             lch/media-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. lch/media-bundle

ActiveSymfony-bundle[File &amp; Storage](/categories/file-storage)

lch/media-bundle
================

Symfony LchMediaBundle

1.2.21(6y ago)16742[6 issues](https://github.com/compagnie-hyperactive/MediaBundle/issues)[1 PRs](https://github.com/compagnie-hyperactive/MediaBundle/pulls)1MITPHPPHP ^7.2

Since Feb 21Pushed 6y ago6 watchersCompare

[ Source](https://github.com/compagnie-hyperactive/MediaBundle)[ Packagist](https://packagist.org/packages/lch/media-bundle)[ Docs](https://github.com/compagnie-hyperactive/MediaBundle)[ RSS](/packages/lch-media-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (5)Versions (23)Used By (1)

MediaBundle
===========

[](#mediabundle)

This bundle brings to you a comprehensive and code-close way of handling media for Symfony 3. Features:

- Defines [media types](#media-types-declaration) in `config.yml`
- Provides [events](#events) to hook on all process (CRUD)
- Provide [form types](#form-types) to interact easily in you admin (pick an existing media/creates a new one)
- Provides Twig extension to ease media display and manipulation in Twig files (get URLs, thumbnails...)
- Provides [validators](#validators) to restrain media to boundaries (size, resolution for images, extensions...)

Installation and pre-requisites
-------------------------------

[](#installation-and-pre-requisites)

Imagick is used to generate thumbnails and images sizes sets. On the GUI side, the bundle use [Bootstrap 4](http://getbootstrap.com/) and [jQuery](https://jquery.com/). Be sure those 2 dependencies are fullfilled, especially on admin screens (media selection/creation)

For installing, use simply : `composer require lch/media-bundle`

Configuration and usage
-----------------------

[](#configuration-and-usage)

1. [General explanations](#general-explanations)
2. [Media types declaration](#media-types-declaration)
3. [Twig extensions and tools](#twig-extension--tools)
4. [Events](#events)
5. [Form types](#form-types)
6. [Validators](#validators)
7. [Storage strategy](#storage-strategy)
8. [Image sizes](#image-sizes)
9. [Practical use cases](#practical-use-cases)
    1. [Download control](#download-control)

### General explanations

[](#general-explanations)

Out of the box, MediaBundle defines 2 types : **image** and **pdf**. You can use those types as base for you custom ones.

Below is shown types and available fields :

[![Media relations and fields](https://camo.githubusercontent.com/6ca126994f72a41c3b8bf3c35fde2dde3aba4ce080dd3e432dbc21bf7d4e30c0/68747470733a2f2f636f6d7061676e69652d68797065726163746976652e6769746875622e696f2f4d6564696142756e646c652f696d616765732f6d656469612d72656c6174696f6e732e706e67)](https://camo.githubusercontent.com/6ca126994f72a41c3b8bf3c35fde2dde3aba4ce080dd3e432dbc21bf7d4e30c0/68747470733a2f2f636f6d7061676e69652d68797065726163746976652e6769746875622e696f2f4d6564696142756e646c652f696d616765732f6d656469612d72656c6174696f6e732e706e67)

### Media types declaration

[](#media-types-declaration)

You need to define your **media types** in `config.yml`. You can define as many types as you need, using the following syntax :

```
    lch_media:
      types:
        image:
          name:             'your_project.image.name' # the translated name for front presentation
          entity:           'YourBundle\Entity\Media\Image' # the entity to be used
          form:             'YourBundle\Form\Media\ImageType' # the form to be used when adding media
          add_view:         'YourBundle/Media/Image/fragments:add.html.twig' # the add form view to be used when adding media
          thumbnail_view:   'YourBundle/Media/Resource/fragments:thumbnail.html.twig' # the view used for displaying thumbnail
          list_item_view:   'YourBundle/Media/Resource/fragments:list.item.html.twig' # the view used for displaying list item in selection lists
          extensions:       ['jpg', 'jpeg', 'png', 'gif'] # allowed extensions
          max_items_per_page: 20 # not required, 20 per default
          thumbnail_sizes:
            news:
              width: 396
              height: 227
```

Let's review an example for each given key :

#### Entity

[](#entity)

Minimal class for above declared image could be :

```
