Configuration
Below is a list of available configuration with default values:
"example" => [
"type" => "anomaly.field_type.relationship",
"config" => [
"related" => null,
"mode" => "lookup",
"key_name" => null,
"title_name" => null,
"value_table" => null,
"selected_table" => null,
"lookup_table" => null,
"default_value" => null,
"handler" => "\Anomaly\RelationshipFieldType\Handler\Related@handle",
]
]
Configuration
Key | Example | Description |
---|---|---|
related |
|
The related model or stream dot notation ( |
mode |
dropdown |
The input mode. Valid options are |
key_name |
slug |
The name of the key field. Default is |
title_name |
name |
The name of the title field. Default is the |
value_table |
|
The builder for the value table. |
selected_table |
|
The builder for the selections table. |
lookup_table |
|
The builder for the lookup table. |
handler |
|
The option handler. |
Option Handlers
Option handlers are responsible for setting the available options on the field type. You can define your own option handler to add your own logic to available options.
You can define custom handlers as a callable string where @handle
will be assumed if no method is provided:
"handler" => \App\Example\MyOptions::class // Assumes @handle
Option handlers can also a handler with a closure:
"example" => [
"config" => [
"handler" => function (RelationshipFieldType $fieldType, ExampleRepositoryInterface $entries) {
$fieldType->setOptions($entries->getCustomEntries()->pluck('title', 'id')->all());
}
]
]
Closures can not be stored in the database so your closure type handlers must be set / overridden from the form builder.{.note}
Writing Option Handlers
Writing custom option handlers is easy. To begin create a class with the method you defined in the config option.
"handler" => "App/Example/MyOptions@handle"
The handler string is called via Laravel's service container. The RelationshipFieldType $fieldType
is passed as an argument.
Handlers are called through Laravel's service container so method and class injection is supported.{.tip}
<?php namespace App/Example;
class MyOptions
{
public function handle(RelationshipFieldType $fieldType, ExampleRepositoryInterface $entries) {
$fieldType->setOptions(
$entries->getCustomEntries()->pluck('title', 'id')->all()
);
}
}