Configuration
Below is the full configuration available with defaults values:
"example" => [
"type" => "anomaly.field_type.state",
"config" => [
"default_value" => null,
"top_options" => null,
"countries" => null,
"mode" => "input",
"handler" => "Anomaly\StateFieldType\Handler\DefaultHandler@handle"
]
]
Configuration
Key | Example | Description |
---|---|---|
default_value |
IL |
The default value. |
countries |
|
The countries to display options for. |
top_options |
|
The top |
mode |
dropdown |
The input mode. Valid options are |
handler |
|
The options handler. |
Addon Configuration
The state options are controlled by the Streams Platform states/*
configuration files. State configuration files are named by country code.
You can override these options by publishing the Streams Platform with:
php artisan streams:publish
Option Handlers
Option handlers are responsible for setting the available state 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/MyStates@handle"
Option handlers can also a handler with a closure:
"example" => [
"config" => [
"handler" => function (StateFieldType $fieldType) {
$fieldType->setOptions(
[
"IL" => config("streams::states/US.available.IL.name"),
"IA" => config("streams::states/US.available.IA.name")
]
);
}
]
]
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/MyStates@handle"
The handler string is called via Laravel's service container. The StateFieldType $fieldType
is passed as an argument.
<?php namespace App\Example;
class MyStates
{
public function handle(StateFieldType $fieldType)
{
$fieldType->setOptions(
[
"IL" => config("streams::states/US.available.IL.name"),
"IA" => config("streams::states/US.available.IA.name")
]
);
}
}