Have you seen our new video tutorials? Check it out!

Files Field Type

The files field type provides a multiple file uploader / selection input.

Introduction

anomaly.field_type.files

The files field type provides a configurable uploader and multiple selection lookup for files from the Files module.

Configuration

Below is a list of available configuration with default values:

"example" => [
    "type"   => "anomaly.field_type.files",
    "config" => [
        "folders"  => [],
        "max_size" => null,
        "min"      => null,
        "max"      => null,
    ]
]
Configuration
Key Example Description

folders

["images", "slides"]

The slugs, paths, or IDs of allowed file folders. Defaults to all folders.

max_size

10

The max size in megabytes allowed for uploads. Defaults to folder configured max then server max.

min

5

The minimum number of selections allowed.

max

5

The maximum number of selections allowed.

Usage

This section will show you how to use the field type via API and in the view layer.

Setting Values

You can set the files field type value with an array of file's ID.

$entry->example = [10, 11, 12];

You can also set the value with a collection of a files.

$entry->example = $files;

Basic Output

The files field type always returns null or a '\Anomaly\FilesModule\File\FileCollection' containing \Anomaly\FilesModule\File\Contract\FileInterface instances.

Example
$entry->example->first()->getName(); // example.jpg
Twig
{{ entry.example.first().getName() }} // example.jpg

Presenter Output

When accessing the field value from a decorated entry model the collection will contain instances of \Anomaly\FilesModule\File\FilePresenter.

Example
$decorated->example->first()->path; // local://folder/file.ext

$decorated->example->first()->make()->url(); // /app/{application}/example/image.jpg
Twig
{{ decorated.example.first().path }} // local://folder/file.ext

{{ decorated.example.first().make.url }} // /app/{application}/example/image.jpg