22
33namespace Backstage \Fields \Concerns ;
44
5+ use Illuminate \Support \Str ;
6+ use Filament \Forms \Components \Select ;
57use Filament \Forms \Components \Hidden ;
8+ use Filament \Schemas \Components \Grid ;
9+ use Illuminate \Support \Facades \Schema ;
610use Filament \Forms \Components \Repeater ;
7- use Filament \Forms \Components \Select ;
811use Filament \Forms \Components \TextInput ;
912use Filament \Schemas \Components \Fieldset ;
10- use Filament \Schemas \Components \Grid ;
13+ use Filament \Forms \Components \CheckboxList ;
1114use Filament \Schemas \Components \Utilities \Get ;
1215use Filament \Schemas \Components \Utilities \Set ;
13- use Illuminate \Support \Facades \Schema ;
14- use Illuminate \Support \Str ;
1516
1617trait HasSelectableValues
1718{
@@ -83,24 +84,14 @@ protected static function ensureFieldConfig(mixed $field, string $type): bool
8384
8485 protected static function shouldHandleRelationshipOptions (mixed $ field , string $ type ): bool
8586 {
86- // Ensure $type is a string to prevent array key errors
87- if (! is_string ($ type )) {
88- return false ;
89- }
90-
91- return isset ($ field ->config [$ type ]) && $ field ->config [$ type ] !== null &&
87+ return isset ($ field ->config [$ type ]) &&
9288 (is_string ($ field ->config [$ type ]) && $ field ->config [$ type ] === 'relationship ' ) ||
9389 (is_array ($ field ->config [$ type ]) && in_array ('relationship ' , $ field ->config [$ type ]));
9490 }
9591
9692 protected static function shouldHandleArrayOptions (mixed $ field , string $ type ): bool
9793 {
98- // Ensure $type is a string to prevent array key errors
99- if (! is_string ($ type )) {
100- return false ;
101- }
102-
103- return isset ($ field ->config [$ type ]) && $ field ->config [$ type ] !== null &&
94+ return isset ($ field ->config [$ type ]) &&
10495 (is_string ($ field ->config [$ type ]) && $ field ->config [$ type ] === 'array ' ) ||
10596 (is_array ($ field ->config [$ type ]) && in_array ('array ' , $ field ->config [$ type ]));
10697 }
@@ -158,7 +149,7 @@ protected static function mergeRelationshipOptions(array $allOptions, array $rel
158149 }
159150
160151 // If both types are selected, group relationship options by resource
161- if (isset ($ field ->config [$ type ]) && $ field -> config [ $ type ] !== null &&
152+ if (isset ($ field ->config [$ type ]) &&
162153 (is_array ($ field ->config [$ type ]) && in_array ('array ' , $ field ->config [$ type ]))) {
163154 return array_merge ($ allOptions , $ relationshipOptions );
164155 } else {
@@ -174,7 +165,7 @@ protected static function mergeArrayOptions(array $allOptions, mixed $field, str
174165 }
175166
176167 // If both types are selected, group array options
177- if (isset ($ field ->config [$ type ]) && $ field -> config [ $ type ] !== null &&
168+ if (isset ($ field ->config [$ type ]) &&
178169 (is_array ($ field ->config [$ type ]) && in_array ('relationship ' , $ field ->config [$ type ]))) {
179170 $ allOptions [__ ('Custom Options ' )] = $ field ->config ['options ' ];
180171 } else {
@@ -204,12 +195,12 @@ protected function selectableValuesFormFields(string $type, string $label, strin
204195 ->schema ([
205196 Grid::make (2 )
206197 ->schema ([
207- Backstage \ Fields \ Fields \ CheckboxList::make ("config. {$ type }" )
198+ CheckboxList::make ("config. {$ type }" )
208199 ->options ([
209200 'array ' => __ ('Array ' ),
210201 'relationship ' => __ ('Relationship ' ),
211202 ])
212- ->afterStateHydrated (function (Forms \ Get $ get , Forms \ Set $ set ) use ($ type ) {
203+ ->afterStateHydrated (function (Get $ get , Set $ set ) use ($ type ) {
213204 $ value = $ get ("config. {$ type }" );
214205
215206 // Set correct config value when creating records
@@ -222,11 +213,11 @@ protected function selectableValuesFormFields(string $type, string $label, strin
222213 ->label (__ ('Options ' ))
223214 ->columnSpanFull ()
224215 ->visible (
225- fn (Forms \ Get $ get ): bool => is_array ($ get ("config. {$ type }" )) && in_array ('array ' , $ get ("config. {$ type }" )) ||
216+ fn (Get $ get ): bool => is_array ($ get ("config. {$ type }" )) && in_array ('array ' , $ get ("config. {$ type }" )) ||
226217 $ get ("config. {$ type }" ) === 'array '
227218 )
228219 ->required (
229- fn (Forms \ Get $ get ): bool => is_array ($ get ("config. {$ type }" )) && in_array ('array ' , $ get ("config. {$ type }" )) ||
220+ fn (Get $ get ): bool => is_array ($ get ("config. {$ type }" )) && in_array ('array ' , $ get ("config. {$ type }" )) ||
230221 $ get ("config. {$ type }" ) === 'array '
231222 ),
232223 // Relationship options
@@ -277,10 +268,10 @@ protected function selectableValuesFormFields(string $type, string $label, strin
277268 })
278269 ->noSearchResultsMessage (__ ('No types found ' ))
279270 ->required (
280- fn (Forms \ Get $ get ): bool => is_array ($ get ("../../config. {$ type }" )) && in_array ('relationship ' , $ get ("../../config. {$ type }" )) ||
271+ fn (Get $ get ): bool => is_array ($ get ("../../config. {$ type }" )) && in_array ('relationship ' , $ get ("../../config. {$ type }" )) ||
281272 $ get ("../../config. {$ type }" ) === 'relationship '
282273 ),
283- Forms \ Components \ Select::make ('relationValue ' )
274+ Select::make ('relationValue ' )
284275 ->label (__ ('Column ' ))
285276 ->helperText (__ ('The column to use as name for the options ' ))
286277 ->options (fn (Get $ get ) => $ get ('relationValue_options ' ) ?? [])
@@ -291,10 +282,10 @@ protected function selectableValuesFormFields(string $type, string $label, strin
291282 ->default ('ulid ' )
292283 ->label (__ ('Key ' ))
293284 ->required (
294- fn (Forms \ Get $ get ): bool => is_array ($ get ("../../config. {$ type }" )) && in_array ('relationship ' , $ get ("../../config. {$ type }" )) ||
285+ fn (Get $ get ): bool => is_array ($ get ("../../config. {$ type }" )) && in_array ('relationship ' , $ get ("../../config. {$ type }" )) ||
295286 $ get ("../../config. {$ type }" ) === 'relationship '
296287 ),
297- Forms \ Components \ Repeater::make ('relationValue_filters ' )
288+ Repeater::make ('relationValue_filters ' )
298289 ->label (__ ('Filters ' ))
299290 ->visible (fn (Get $ get ): bool => ! empty ($ get ('resource ' )))
300291 ->schema ([
@@ -347,7 +338,7 @@ protected function selectableValuesFormFields(string $type, string $label, strin
347338 ]),
348339 ])
349340 ->visible (
350- fn (Forms \ Get $ get ): bool => is_array ($ get ("config. {$ type }" )) && in_array ('relationship ' , $ get ("config. {$ type }" )) ||
341+ fn (Get $ get ): bool => is_array ($ get ("config. {$ type }" )) && in_array ('relationship ' , $ get ("config. {$ type }" )) ||
351342 $ get ("config. {$ type }" ) === 'relationship '
352343 )
353344 ->columnSpanFull (),
0 commit comments