# C. MediaLibrary

## New feature: media rework && media library

Concepts:

- library can manage files referenced using a "mapping"
- default mappings are "file" and "image"
- for each LinkedMediaType, mapping types must be configured using LinkedMedia attribute
- the form type is then only capable of displaying/adding in its mappings
- link is stored as string in database (json for collection) so multiple configurations are possible (heterogeneous media in same collection or multiple media usable for one simple link)
- media are now stored in a subdir matching Site slug
- Finally, all previous file/image systems are preserved and will be deprecated later.


## Usage

LinkedMediaType && LinkedMediaCollectionType

(yaml form type strings: linked_media && linked_media_collection)

-> Permit to soft-link media stored and accessed through media library.

```php
#[ORM\Column(type: Types::STRING, length: 255)]
#[LinkedMedia(mappings: ['image', 'file'])]
private ?string $linkedMedia = null;
```

```php
#[ORM\Column(type: Types::JSON)]
#[LinkedMedia(mappings: ['image'])]
private ?array $linkedMediaCollec = [];
```

### Mappings

Mappings are used to change where and how are media handled, can be public or private, max preview size, change storage directory, mime types accepted, etc.

Default mappings available:
```
'image'
'private_image'
'file'
'private_file'
```

Default mappings config can be overriden in auto_admin_content.yaml, under auto_admin>media>media_mappings

## Upgrade requirements

New routing registering:

```yaml
# config\routes.yaml

# append in not already in routes file

app_extra:
  resource: .
  type: aa

```


## Unimplemented yet:

- mappings will later be able to isolate private files from public-accessed directories
- image media resize/crop
- media rename
- media translation edit (can be hacked to use default admin interfaces for mapping class)