44
55namespace Relaticle \CustomFields \Livewire ;
66
7+ use Closure ;
78use Filament \Actions \Action ;
89use Filament \Actions \ActionGroup ;
910use Filament \Actions \Concerns \InteractsWithActions ;
@@ -28,10 +29,18 @@ final class ManageCustomFieldSection extends Component implements HasActions, Ha
2829 use InteractsWithForms;
2930 use ManagesFields;
3031
32+ /** @var ?Closure(CustomFieldSection): ?Closure */
33+ private static ?Closure $ uniqueRuleModifierResolver = null ;
34+
3135 public string $ entityType ;
3236
3337 public CustomFieldSection $ section ;
3438
39+ public static function resolveUniqueRuleModifierUsing (?Closure $ callback ): void
40+ {
41+ self ::$ uniqueRuleModifierResolver = $ callback ;
42+ }
43+
3544 public function updateFieldsOrder (int |string $ sectionId , array $ fields ): void
3645 {
3746 $ model = CustomFields::newCustomFieldModel ();
@@ -66,12 +75,22 @@ public function actions(): ?ActionGroup
6675
6776 public function editAction (): Action
6877 {
78+ $ sectionForm = SectionForm::entityType ($ this ->entityType );
79+
80+ if (self ::$ uniqueRuleModifierResolver ) {
81+ $ modifier = (self ::$ uniqueRuleModifierResolver )($ this ->section );
82+
83+ if ($ modifier ) {
84+ $ sectionForm ->modifyUniqueRuleUsing ($ modifier );
85+ }
86+ }
87+
6988 return Action::make ('edit ' )
7089 ->icon ('heroicon-o-pencil-square ' )
7190 ->model (CustomFields::sectionModel ())
7291 ->slideOver (false )
7392 ->record ($ this ->section )
74- ->schema (SectionForm:: entityType ( $ this -> entityType ) ->schema ())
93+ ->schema ($ sectionForm ->schema ())
7594 ->fillForm ($ this ->section ->toArray ())
7695 ->action (fn (array $ data ): bool => ! $ this ->section ->hasSystemDefinedFields () && $ this ->section ->update ($ data ))
7796 ->visible (fn (CustomFieldSection $ record ): bool => ! $ record ->hasSystemDefinedFields ())
0 commit comments