1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebTheory\Saveyour\Fields; |
4
|
|
|
|
5
|
|
|
use WebTheory\Html\AbstractHtmlElement; |
6
|
|
|
use WebTheory\Saveyour\Contracts\FormFieldInterface; |
7
|
|
|
use WebTheory\Saveyour\Elements\Label; |
8
|
|
|
|
9
|
|
|
abstract class AbstractFormField extends AbstractHtmlElement implements FormFieldInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $name = ''; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var mixed |
18
|
|
|
*/ |
19
|
|
|
protected $value; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $label = ''; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $placeholder = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
protected $required = false; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var bool |
38
|
|
|
*/ |
39
|
|
|
protected $disabled = false; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
protected $readonly = false; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the value of name |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
3 |
|
public function getName(): string |
52
|
|
|
{ |
53
|
3 |
|
return $this->name; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set the value of name |
58
|
|
|
* |
59
|
|
|
* @param string $name |
60
|
|
|
* |
61
|
|
|
* @return self |
62
|
|
|
*/ |
63
|
15 |
|
public function setName(string $name) |
64
|
|
|
{ |
65
|
15 |
|
$this->name = $name; |
66
|
|
|
|
67
|
15 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the value of value |
72
|
|
|
* |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
6 |
|
public function getValue() |
76
|
|
|
{ |
77
|
6 |
|
return $this->value; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Set the value of value |
82
|
|
|
* |
83
|
|
|
* @param mixed $value |
84
|
|
|
* |
85
|
|
|
* @return self |
86
|
|
|
*/ |
87
|
6 |
|
public function setValue($value) |
88
|
|
|
{ |
89
|
6 |
|
$this->value = $value; |
90
|
|
|
|
91
|
6 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get the value of label |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
*/ |
99
|
|
|
public function getLabel(): string |
100
|
|
|
{ |
101
|
|
|
return $this->label; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Set the value of label |
106
|
|
|
* |
107
|
|
|
* @param string $label |
108
|
|
|
* |
109
|
|
|
* @return self |
110
|
|
|
*/ |
111
|
|
|
public function setLabel(string $label) |
112
|
|
|
{ |
113
|
|
|
$this->label = $label; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get the value of required |
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
|
|
public function isRequired(): bool |
124
|
|
|
{ |
125
|
|
|
return $this->required; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Set the value of required |
130
|
|
|
* |
131
|
|
|
* @param bool $required |
132
|
|
|
* |
133
|
|
|
* @return self |
134
|
|
|
*/ |
135
|
|
|
public function setRequired(bool $required) |
136
|
|
|
{ |
137
|
|
|
$this->required = $required; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get the value of disabled |
144
|
|
|
* |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
|
|
public function isDisabled(): bool |
148
|
|
|
{ |
149
|
|
|
return $this->disabled; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set the value of disabled |
154
|
|
|
* |
155
|
|
|
* @param bool $disabled |
156
|
|
|
* |
157
|
|
|
* @return self |
158
|
|
|
*/ |
159
|
|
|
public function setDisabled(bool $disabled) |
160
|
|
|
{ |
161
|
|
|
$this->disabled = $disabled; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get the value of readOnly |
168
|
|
|
* |
169
|
|
|
* @return bool |
170
|
|
|
*/ |
171
|
|
|
public function isReadOnly(): bool |
172
|
|
|
{ |
173
|
|
|
return $this->readonly; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Set the value of readOnly |
178
|
|
|
* |
179
|
|
|
* @param bool $readonly |
180
|
|
|
* |
181
|
|
|
* @return self |
182
|
|
|
*/ |
183
|
|
|
public function setReadOnly(bool $readonly) |
184
|
|
|
{ |
185
|
|
|
$this->readonly = $readonly; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get the value of placeholder |
192
|
|
|
* |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function getPlaceholder(): string |
196
|
|
|
{ |
197
|
|
|
return $this->placeholder; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Set the value of placeholder |
202
|
|
|
* |
203
|
|
|
* @param string $placeholder |
204
|
|
|
* |
205
|
|
|
* @return self |
206
|
|
|
*/ |
207
|
|
|
public function setPlaceholder(string $placeholder) |
208
|
|
|
{ |
209
|
|
|
$this->placeholder = $placeholder; |
210
|
|
|
|
211
|
|
|
return $this; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return string |
216
|
|
|
*/ |
217
|
|
|
public function getLabelHtml(): Label |
218
|
|
|
{ |
219
|
|
|
return (new Label($this->label))->setFor($this->id)->toHtml(); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|