diff --git a/config/livewire-forms.php b/config/livewire-forms.php index e12daff3..3038741f 100644 --- a/config/livewire-forms.php +++ b/config/livewire-forms.php @@ -23,6 +23,7 @@ Statamic\Fieldtypes\Text::class => Aerni\LivewireForms\Fields\Text::class, Statamic\Fieldtypes\Textarea::class => Aerni\LivewireForms\Fields\Textarea::class, Statamic\Fieldtypes\Toggle::class => Aerni\LivewireForms\Fields\Toggle::class, + Statamic\Fieldtypes\Dictionary::class => Aerni\LivewireForms\Fields\Dictionary::class, ], /* diff --git a/resources/views/default/fields/dictionary.blade.php b/resources/views/default/fields/dictionary.blade.php new file mode 100644 index 00000000..05c07b63 --- /dev/null +++ b/resources/views/default/fields/dictionary.blade.php @@ -0,0 +1 @@ +@include('livewire.forms.default.fields.select') \ No newline at end of file diff --git a/src/Fields/Dictionary.php b/src/Fields/Dictionary.php new file mode 100644 index 00000000..f45a4a1c --- /dev/null +++ b/src/Fields/Dictionary.php @@ -0,0 +1,42 @@ +max_items > 1; + } + + public function dictionary(): DictionaryInstance + { + $config = $this->field->config(); + $config = is_array($config) ? Arr::get($config, 'dictionary') : $config; + $config = is_array($config) ? $config : ['type' => $config]; + + if (! $handle = Arr::pull($config, 'type')) { + throw new UndefinedDictionaryException; + } + + if ($dictionary = Dictionaries::find($handle, $config)) { + return $dictionary; + } + + throw new DictionaryNotFoundException($handle); + } + + public function optionsProperty(?array $options = null): array + { + return $this->dictionary()->options(); + } +}