88use Aerni \LivewireForms \Livewire \Synthesizers \FieldSynth ;
99use Aerni \LivewireForms \Livewire \Synthesizers \RuleSynth ;
1010use Illuminate \Support \Facades \Blade ;
11+ use Illuminate \Support \Facades \File ;
1112use Illuminate \Support \Facades \Validator ;
13+ use Illuminate \Support \Str ;
1214use Livewire \Livewire ;
15+ use Statamic \Facades \Form ;
1316use Statamic \Providers \AddonServiceProvider ;
1417
1518class ServiceProvider extends AddonServiceProvider
@@ -35,7 +38,8 @@ public function bootAddon()
3538 ->bootBladeDirectives ()
3639 ->bootValidators ()
3740 ->bootLivewire ()
38- ->bootSelectableFieldtypes ();
41+ ->bootSelectableFieldtypes ()
42+ ->bootFormConfigFields ();
3943 }
4044
4145 protected function bootBladeDirectives (): self
@@ -73,4 +77,47 @@ protected function bootSelectableFieldtypes(): self
7377
7478 return $ this ;
7579 }
80+
81+ protected function bootFormConfigFields (): self
82+ {
83+ Form::appendConfigFields ('* ' , __ ('Livewire Forms ' ), [
84+ 'type ' => [
85+ 'type ' => 'button_group ' ,
86+ 'display ' => __ ('Type ' ),
87+ 'instructions ' => __ ('Choose the desired type for this form. ' ),
88+ 'options ' => [
89+ 'basic ' => __ ('Basic ' ),
90+ 'wizard ' => __ ('Wizard ' ),
91+ ],
92+ 'default ' => 'basic ' ,
93+ ],
94+ 'view ' => [
95+ 'type ' => 'select ' ,
96+ 'display ' => __ ('View ' ),
97+ 'instructions ' => __ ('Choose the view for this form. ' ),
98+ 'options ' => collect (File::files (resource_path ('views/ ' .config ('livewire-forms.view_path ' ))))
99+ ->map (fn ($ file ) => Str::before ($ file ->getBasename (), '. ' ))
100+ ->mapWithKeys (fn ($ view ) => [$ view => str ($ view )->replace (['_ ' , '- ' ], ' ' )->title ()->toString ()]),
101+ 'clearable ' => true ,
102+ 'width ' => 50 ,
103+ ],
104+ 'theme ' => [
105+ 'type ' => 'select ' ,
106+ 'display ' => __ ('Theme ' ),
107+ 'instructions ' => __ ('Choose the theme for this form. ' ),
108+ 'options ' => collect (File::directories (resource_path ('views/ ' .config ('livewire-forms.view_path ' ))))
109+ ->map (fn ($ directory ) => basename ($ directory ))
110+ ->mapWithKeys (fn ($ theme ) => [$ theme => str ($ theme )->replace (['_ ' , '- ' ], ' ' )->title ()->toString ()]),
111+ 'clearable ' => true ,
112+ 'width ' => 50 ,
113+ ],
114+ 'redirect ' => [
115+ 'type ' => 'link ' ,
116+ 'display ' => __ ('Redirect URL ' ),
117+ 'instructions ' => __ ('The users will be redirected to this URL after the form was submitted. ' ),
118+ ],
119+ ]);
120+
121+ return $ this ;
122+ }
76123}
0 commit comments