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

File Field Type

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

Introduction

anomaly.field_type.file

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

Configuration

Below is a list of available configuration with default values:

"example" => [
    "type"   => "anomaly.field_type.file",
    "config" => [
        "default_value" => null,
        "folders"       => [],
        "max"           => null,
    ]
]
Configuration
Key Example Description

default_value

12

The default value defined as a file ID.

folders

["images", "slides"]

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

max

10

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

Usage

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

Basic Output

The file field type always returns null or an \Anomaly\FilesModule\File\Contract\FileInterface instance.

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

Setting Values

You can set the file field type value with a file's ID.

$entry->example = 10;

You can also set the value with an instance of a file.

$entry->example = $file;

Lastly you can set the value with an instance of a file presenter.

$entry->example = $decorated;

Presenter Output

When accessing the field value from a decorated entry model the an instance of \Anomaly\FilesModule\File\FilePresenter will be returned.

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

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

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