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

Polymorphic Field Type

The polymorphic field type a clean API to establish polymorphic relations.

Introduction

anomaly.field_type.polymorphic

The polymorphic field type a clean API to establish polymorphic relations between objects.

Notice: This field type is intended for API use only and does not have a UI at this time.

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

$entry->example = $entry;

You can also set the polymorphic field type value with a decorated model:

$entry->example = $decorated;

Basic Output

The polymorphic field type always returns null or an \Anomaly\Streams\Platform\Entry\EntryInterface instance.

Example
$entry->example->getId();
Twig
{{ entry.example.id }}

Presenter Output

When accessing the field value from a decorated entry model the an instance of \Anomaly\Streams\Platform\Entry\EntryPresenter will be returned.

Example
$decorated->example->test;
Twig
{{ decorated.example.test }}