Configuration
Below is the full configuration available with defaults values:
"example" => [
"type" => "anomaly.field_type.country"
,
"config" => [
"default_value" => null,
"top_options" => null,
"mode" => "input",
"handler" => "Anomaly\CountryFieldType\Handler\DefaultHandler@handle"
]
]
Configuration
Key | Example | Description |
---|---|---|
default_value |
US |
The default value. |
top_options |
|
The top |
mode |
dropdown |
The input mode. Valid options are |
handler |
|
The options handler. |
Addon Configuration
The country options are controlled by the Streams Platform countries.php
configuration file.
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 country 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/MyCountries@handle"
Option handlers can also a handler with a closure:
"example" => [
"config" => [
"handler" => function (CountryFieldType $fieldType) {
$fieldType->setOptions(
[
"US" => "streams::country.US",
"CA" => "streams::country.CA"
]
);
}
]
]
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/MyCountries@handle"
The handler string is called via Laravel's service container. The CountryFieldType $fieldType
is passed as an argument.
<?php namespace App\Example;
class MyCountries
{
public function handle(CountryFieldType $fieldType)
{
$fieldType->setOptions(
[
"US" => "anomaly.field_type.country::country.US",
"CA" => "anomaly.field_type.country::country.CA",
]
);
}
}