Introduction

anomaly.field_type.repeater

The repeater field type adds repeating data structures to your forms.

Configuration

Below is a list of available configuration with default values:

"example" => [
    "type"   => "anomaly.field_type.repeater",
    "config" => [
        "related"        => null,
        "max"            => null,
        "min"            => null,
        "add_row"        => "anomaly.field_type.repeater::button.add_row",
    ]
]
Configuration
Key Example Description

related

\Anomaly\RepeatersModule\Example\ExampleModel::class

The related repeater model. You can also define any model via API.

max

5

The maximum items allowed.

min

2

The minimum items allowed.

add_row

module::button.add_example

The translatable text for the "add row" button.

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 repeater field type value with a model instance:

$entry->example = $entry;

You can set the value with a collection of instances too:

$entry->example = $collection;

Lastly you can set the repeater field type value with an array of entry IDs:

$entry->example = [7, 8];

Basic Output

The repeater field type always returns an \Anomaly\Streams\Platform\Entry\EntryCollection instance of related repeater models.

Example
$entry->example; // Collection of models.
Twig
{% for entry in entry.example %}
    <h2>{{ entry.title }}</h2>
    <p>{{ entry.description }}</p>
{% endfor %}

Presenter Output

When accessing the field value from a decorated entry model the collection will contain instances of \Anomaly\Streams\Platform\Entry\EntryPresenter.

Example
$decorated->example->first()->title;
Twig
{{ decorated.example.first().title }}