|
3 | 3 | namespace Kirby\Form; |
4 | 4 |
|
5 | 5 | use Kirby\Cms\HasSiblings; |
| 6 | +use Kirby\Cms\ModelWithContent; |
| 7 | +use Kirby\Exception\NotFoundException; |
6 | 8 | use Kirby\Toolkit\HasI18n; |
7 | 9 |
|
8 | 10 | /** |
@@ -39,40 +41,54 @@ abstract class FieldClass |
39 | 41 | use Mixin\When; |
40 | 42 | use Mixin\Width; |
41 | 43 |
|
42 | | - protected Fields $siblings; |
43 | | - |
44 | 44 | public function __construct( |
45 | | - protected array $params = [] |
| 45 | + array|string|null $after = null, |
| 46 | + bool $autofocus = false, |
| 47 | + array|string|null $before = null, |
| 48 | + mixed $default = null, |
| 49 | + bool $disabled = false, |
| 50 | + array|string|null $help = null, |
| 51 | + string|null $icon = null, |
| 52 | + array|string|null $label = null, |
| 53 | + ModelWithContent|null $model = null, |
| 54 | + protected string|null $name = null, |
| 55 | + array|string|null $placeholder = null, |
| 56 | + bool $required = false, |
| 57 | + protected Fields|null $siblings = null, |
| 58 | + bool $translate = true, |
| 59 | + $value = null, |
| 60 | + array|null $when = null, |
| 61 | + string|null $width = null |
46 | 62 | ) { |
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']); |
| 63 | + $this->setAfter($after); |
| 64 | + $this->setAutofocus($autofocus); |
| 65 | + $this->setBefore($before); |
| 66 | + $this->setDefault($default); |
| 67 | + $this->setDisabled($disabled); |
| 68 | + $this->setHelp($help); |
| 69 | + $this->setIcon($icon); |
| 70 | + $this->setLabel($label); |
| 71 | + $this->setModel($model); |
| 72 | + $this->setName($name); |
| 73 | + $this->setPlaceholder($placeholder); |
| 74 | + $this->setRequired($required); |
| 75 | + $this->setSiblings($siblings); |
| 76 | + $this->setTranslate($translate); |
| 77 | + $this->setWhen($when); |
| 78 | + $this->setWidth($width); |
| 79 | + |
| 80 | + if ($value !== null) { |
| 81 | + $this->fill($value); |
66 | 82 | } |
67 | 83 | } |
68 | 84 |
|
69 | 85 | public function __call(string $param, array $args): mixed |
70 | 86 | { |
71 | | - if (isset($this->$param) === true) { |
| 87 | + if (property_exists($this, $param) === true) { |
72 | 88 | return $this->$param; |
73 | 89 | } |
74 | 90 |
|
75 | | - return $this->params[$param] ?? null; |
| 91 | + throw new NotFoundException(message: 'Method or option "' . $param . '" does not exist for field type "' . $this->type() . '"'); |
76 | 92 | } |
77 | 93 |
|
78 | 94 | /** |
@@ -101,14 +117,6 @@ public function isHidden(): bool |
101 | 117 | return false; |
102 | 118 | } |
103 | 119 |
|
104 | | - /** |
105 | | - * Returns all original params for the field |
106 | | - */ |
107 | | - public function params(): array |
108 | | - { |
109 | | - return $this->params; |
110 | | - } |
111 | | - |
112 | 120 | /** |
113 | 121 | * Define the props that will be sent to |
114 | 122 | * the Vue component |
|
0 commit comments