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/[email protected]"

Option handlers can also a handler with a closure:

"example" => [
    "config" => [
        "handler" => function (TagsFieldType $fieldType) {
            $fieldType->setOptions(
                [
                    "foo",
                    "bar"
                ]
            );
        }
    ]
]

Closures can not be stored in the database so your closure type handlers must be set / overridden from the form builder.

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/[email protected]"

The handler string is called via Laravel's service container. The TagsFieldType $fieldType is passed as an argument.

Handlers are called through Laravel's service container so method and class injection is supported.

<?php namespace App\Example;

use Anomaly\TagsFieldType\TagsFieldType;

class MyTags
{
    public function handle(TagsFieldType $fieldType)
    {
        $fieldType->setOptions(
            [
                "foo",
                "bar",
            ]
        );
    }
}