55use Codedor \LinkPicker \Facades \LinkCollection ;
66use Codedor \LinkPicker \Link ;
77use Codedor \LocaleCollection \Facades \LocaleCollection ;
8- use Filament \Forms \Components \Actions \Action ;
98use Filament \Forms \Components \Checkbox ;
10- use Filament \Forms \Components \Component ;
119use Filament \Forms \Components \Field ;
1210use Filament \Forms \Components \Select ;
13- use Filament \Forms \Form ;
14- use Filament \Forms \Get ;
15- use Filament \Forms \Set ;
11+ use Filament \Schemas \Components \Grid ;
1612use Illuminate \Database \Eloquent \Model ;
1713use Illuminate \Routing \Route ;
1814use Illuminate \Support \Arr ;
@@ -31,84 +27,47 @@ protected function setUp(): void
3127 parent ::setUp ();
3228
3329 $ this ->registerActions ([
34- Action::make ('link-picker-modal ' )
30+ \ Filament \ Actions \ Action::make ('link-picker-modal ' )
3531 ->label (fn ($ state ) => $ state
3632 ? __ ('filament-link-picker::input.edit link ' )
3733 : __ ('filament-link-picker::input.select link ' )
3834 )
3935 ->icon (fn ($ state ) => $ state ? 'heroicon-o-pencil ' : 'heroicon-o-plus ' )
4036 ->color ('gray ' )
4137 ->iconSize ('sm ' )
42- ->fillForm (function (Get $ get , Component $ component , \Livewire \Component $ livewire ): array {
43- $ statePath = $ component ->getStatePath (false );
44-
45- $ schema = $ this ->getFormSchemaForRoute ($ get ("{$ statePath }.route " ));
46-
47- $ state = [
48- 'route ' => $ get ("{$ statePath }.route " ),
49- 'newTab ' => $ get ("{$ statePath }.newTab " ),
50- 'parameters ' => $ get ("{$ statePath }.parameters " ) ?: [],
38+ ->fillForm (fn (\Filament \Schemas \Components \Component $ component ): array => $ component ->getState () ?? [])
39+ ->schema (function () {
40+ return [
41+ Grid::make (1 )->schema (function (\Livewire \Component $ livewire ) {
42+ $ mountedAction = Arr::last ($ livewire ->mountedActions );
43+ $ mountedActionIndex = array_key_last ($ livewire ->mountedActions );
44+ $ schema = $ this ->getFormSchemaForRoute ($ mountedAction ['data ' ]['route ' ] ?? null );
45+
46+ // since the fields are dynamic we have to fill the state manually,
47+ // else validation will fail because property is not in the state
48+ data_fill ($ livewire , "mountedActions. {$ mountedActionIndex }.data.parameters " , []);
49+ $ schema ->each (function (Field $ field ) use (&$ livewire , $ mountedActionIndex ) {
50+ data_fill (
51+ $ livewire ,
52+ "mountedActions. {$ mountedActionIndex }.data. {$ field ->statePath }" ,
53+ null ,
54+ );
55+ });
56+
57+ return $ schema ->toArray ();
58+ }),
5159 ];
52-
53- $ actionNestingIndex = array_key_last ($ livewire ->mountedFormComponentActions );
54-
55- $ schema
56- ->each (function (Field $ field ) use (&$ state , $ statePath , $ get , $ actionNestingIndex , $ livewire ) {
57- $ fieldStatePath = $ field ->statePath ;
58-
59- data_fill (
60- $ state ,
61- $ fieldStatePath ,
62- data_get (
63- $ livewire ->mountedFormComponentActionsData [$ actionNestingIndex ] ?? [],
64- "{$ statePath }. {$ fieldStatePath }"
65- ) ?? $ get ("{$ statePath }. {$ fieldStatePath }" ) ?? null
66- );
67- });
68-
69- return $ state ;
70- })
71- ->form (function (Get $ get , Component $ component , \Livewire \Component $ livewire , Form $ form ) {
72- $ statePath = $ component ->getStatePath (false );
73-
74- $ actionNestingIndex = array_key_last ($ livewire ->mountedFormComponentActions );
75-
76- $ schema = $ this ->getFormSchemaForRoute (
77- $ livewire ->mountedFormComponentActionsData [$ actionNestingIndex ]['route ' ] ?? $ get ("{$ statePath }.route " ) ?? null
78- );
79-
80- $ state = $ livewire ->mountedFormComponentActionsData [$ actionNestingIndex ] ?? [];
81-
82- // since the fields are dynamic we have to fill the state manually,
83- // else validation will fail because property is not in the state
84- $ schema ->each (function (Field $ field ) use (&$ state , $ statePath , $ get , $ actionNestingIndex , $ livewire ) {
85- $ fieldStatePath = $ field ->statePath ;
86-
87- data_fill (
88- $ state ,
89- $ fieldStatePath ,
90- data_get (
91- $ livewire ->mountedFormComponentActionsData [$ actionNestingIndex ] ?? [],
92- "{$ statePath }. {$ fieldStatePath }"
93- ) ?? $ get ("{$ statePath }. {$ fieldStatePath }" ) ?? null
94- );
95- });
96-
97- $ livewire ->mountedFormComponentActionsData [$ actionNestingIndex ] = $ state ;
98- $ form ->fill ($ state );
99-
100- return $ schema ->toArray ();
10160 })
102- ->action (function (Set $ set , array $ data , Component $ component ) {
61+ ->action (function (\ Filament \ Schemas \ Components \ Utilities \ Set $ set , array $ data , \ Filament \ Schemas \ Components \ Component $ component ) {
10362 $ set ($ component ->getStatePath (false ), $ data );
10463 }),
10564
106- Action::make ('link-picker-clear ' )
65+ \ Filament \ Actions \ Action::make ('link-picker-clear ' )
10766 ->label (__ ('filament-link-picker::input.remove link ' ))
10867 ->icon ('heroicon-o-trash ' )
10968 ->iconSize ('sm ' )
11069 ->color ('danger ' )
111- ->action (function (Set $ set ) {
70+ ->action (function (\ Filament \ Schemas \ Components \ Utilities \ Set $ set ) {
11271 $ set ($ this ->getStatePath (false ), null );
11372 }),
11473 ]);
@@ -216,8 +175,8 @@ private function getFormSchemaForRoute(?string $selectedRoute): Collection
216175
217176 $ schema ->add (
218177 Select::make ('parameters.anchor ' )
219- ->hidden (fn (Get $ get ) => ! $ get ("parameters. {$ anchorData ['parameter ' ]}" ))
220- ->options (function (Get $ get ) use ($ anchorData ) {
178+ ->hidden (fn (\ Filament \ Schemas \ Components \ Utilities \ Get $ get ) => ! $ get ("parameters. {$ anchorData ['parameter ' ]}" ))
179+ ->options (function (\ Filament \ Schemas \ Components \ Utilities \ Get $ get ) use ($ anchorData ) {
221180 /**
222181 * @var Model $record
223182 */
0 commit comments