33namespace Kirby \Form ;
44
55use Kirby \Cms \HasSiblings ;
6+ use Kirby \Cms \ModelWithContent ;
7+ use Kirby \Exception \NotFoundException ;
68use Kirby \Toolkit \HasI18n ;
79
810/**
@@ -26,6 +28,7 @@ abstract class FieldClass
2628 use Mixin \Api;
2729 use Mixin \Autofocus;
2830 use Mixin \Before;
31+ use Mixin \Disabled;
2932 use Mixin \Help;
3033 use Mixin \Icon;
3134 use Mixin \Label;
@@ -37,42 +40,54 @@ abstract class FieldClass
3740 use Mixin \When;
3841 use Mixin \Width;
3942
40- protected bool $ disabled ;
41- protected string |null $ name ;
42- protected Fields $ siblings ;
43-
4443 public function __construct (
45- protected array $ params = []
44+ array |string |null $ after = null ,
45+ bool $ autofocus = false ,
46+ array |string |null $ before = null ,
47+ mixed $ default = null ,
48+ bool $ disabled = false ,
49+ array |string |null $ help = null ,
50+ string |null $ icon = null ,
51+ array |string |null $ label = null ,
52+ ModelWithContent |null $ model = null ,
53+ protected string |null $ name = null ,
54+ array |string |null $ placeholder = null ,
55+ bool $ required = false ,
56+ protected Fields |null $ siblings = null ,
57+ bool $ translate = true ,
58+ $ value = null ,
59+ array |null $ when = null ,
60+ string |null $ width = null
4661 ) {
47- $ this ->setAfter ($ params [ ' after ' ] ?? null );
48- $ this ->setAutofocus ($ params [ ' autofocus ' ] ?? false );
49- $ this ->setBefore ($ params [ ' before ' ] ?? null );
50- $ this ->setDefault ($ params [ ' default ' ] ?? null );
51- $ this ->setDisabled ($ params [ ' disabled ' ] ?? false );
52- $ this ->setHelp ($ params [ ' help ' ] ?? null );
53- $ this ->setIcon ($ params [ ' icon ' ] ?? null );
54- $ this ->setLabel ($ params [ ' label ' ] ?? null );
55- $ this ->setModel ($ params [ ' model ' ] ?? null );
56- $ this ->setName ($ params [ ' name ' ] ?? null );
57- $ this ->setPlaceholder ($ params [ ' placeholder ' ] ?? null );
58- $ this ->setRequired ($ params [ ' required ' ] ?? false );
59- $ this ->setSiblings ($ params [ ' siblings ' ] ?? null );
60- $ this ->setTranslate ($ params [ ' translate ' ] ?? true );
61- $ this ->setWhen ($ params [ ' when ' ] ?? null );
62- $ this ->setWidth ($ params [ ' width ' ] ?? null );
63-
64- if (array_key_exists ( ' value ' , $ params ) === true ) {
65- $ this ->fill ($ params [ ' value ' ] );
62+ $ this ->setAfter ($ after );
63+ $ this ->setAutofocus ($ autofocus );
64+ $ this ->setBefore ($ before );
65+ $ this ->setDefault ($ default );
66+ $ this ->setDisabled ($ disabled );
67+ $ this ->setHelp ($ help );
68+ $ this ->setIcon ($ icon );
69+ $ this ->setLabel ($ label );
70+ $ this ->setModel ($ model );
71+ $ this ->setName ($ name );
72+ $ this ->setPlaceholder ($ placeholder );
73+ $ this ->setRequired ($ required );
74+ $ this ->setSiblings ($ siblings );
75+ $ this ->setTranslate ($ translate );
76+ $ this ->setWhen ($ when );
77+ $ this ->setWidth ($ width );
78+
79+ if ($ value !== null ) {
80+ $ this ->fill ($ value );
6681 }
6782 }
6883
6984 public function __call (string $ param , array $ args ): mixed
7085 {
71- if (isset ($ this -> $ param ) === true ) {
86+ if (property_exists ($ this , $ param ) === true ) {
7287 return $ this ->$ param ;
7388 }
7489
75- return $ this ->params [ $ param ] ?? null ;
90+ throw new NotFoundException (message: ' Method or option " ' . $ param . ' " does not exist for field type " ' . $ this ->type () . ' " ' ) ;
7691 }
7792
7893 /**
@@ -83,14 +98,6 @@ public function dialogs(): array
8398 return [];
8499 }
85100
86- /**
87- * If `true`, the field is no longer editable and will not be saved
88- */
89- public function disabled (): bool
90- {
91- return $ this ->disabled ;
92- }
93-
94101 /**
95102 * Returns optional drawer routes for the field
96103 */
@@ -104,11 +111,6 @@ public function id(): string
104111 return $ this ->name ();
105112 }
106113
107- public function isDisabled (): bool
108- {
109- return $ this ->disabled ;
110- }
111-
112114 public function isHidden (): bool
113115 {
114116 return false ;
@@ -122,14 +124,6 @@ public function name(): string
122124 return $ this ->name ?? $ this ->type ();
123125 }
124126
125- /**
126- * Returns all original params for the field
127- */
128- public function params (): array
129- {
130- return $ this ->params ;
131- }
132-
133127 /**
134128 * Define the props that will be sent to
135129 * the Vue component
@@ -167,11 +161,6 @@ public function reset(): static
167161 return $ this ;
168162 }
169163
170- protected function setDisabled (bool $ disabled = false ): void
171- {
172- $ this ->disabled = $ disabled ;
173- }
174-
175164 protected function setName (string |null $ name = null ): void
176165 {
177166 $ this ->name = strtolower ($ name ?? $ this ->type ());
0 commit comments