Configuration
Below is the full configuration available with defaults values:
"example" => [
"type" => "anomaly.field_type.colorpicker",
"config" => [
"default_value" => null,
"format" => "hex",
"colors" => null,
"handler" => "Anomaly\ColorpickerFieldType\Handler\DefaultHandler@handle",
]
]
Configuration
Key | Example | Description |
---|---|---|
default_value |
|
The default value. |
format |
code |
The color format to display. Valid options are |
colors |
|
Predefined color swatches. |
handler |
|
The predefined color handler. |
Color Handlers
Color handlers are responsible for setting the predefined colors on the field type. You can define your own handler to add your own logic to predefined color options.
You can define custom handlers as a callable string where @handle
will be assumed if no method is provided:
"handler" => "App/Example/MyColors@handle"
Color handlers can also a handler with a closure:
"example" => [
"config" => [
"handler" => function (ColorpickerFieldType $fieldType) {
$fieldType->setOptions(
[
"#61259e",
"#38b5e6",
"#24ce7b"
]
);
}
]
]
Closures can not be stored in the database so your closure type handlers must be set / overridden from the form builder.{.note}
Writing Color Handlers
Writing custom color handlers is easy. To begin create a class with the method you defined in the config option.
"handler" => "App/Example/MyColors@handle"
The handler string is called via Laravel's service container. The ColorpickerFieldType $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 MyColors
{
public function handle(ColorpickerFieldType $fieldType)
{
$fieldType->setOptions(
[
"#61259e",
"#38b5e6",
"#24ce7b"
]
);
}
}