PluginProbe
The Innovative Form Builder – IvyForms / 0.3.1
The Innovative Form Builder – IvyForms v0.3.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Entity / Field / Field.php

Field.php in The Innovative Form Builder – IvyForms 0.3.1, at backend/src/Entity/Field/Field.php

339 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Entity\Field;
4
5 // phpcs:disable PSR1.Files.SideEffects
6 if (!defined('ABSPATH')) {
7 exit; // Exit if accessed directly
8 }
9
10 use IvyForms\ValueObjects\Field\Field as FieldValueObject;
11
12 /**
13 * Class Field
14 *
15 * @package IvyForms\Entity\Field
16 */
17 class Field
18 {
19 /**
20 * @var FieldValueObject
21 */
22 private FieldValueObject $formField;
23
24 /**
25 * Field constructor.
26 *
27 * @param FieldValueObject $formField The form field object.
28 */
29 public function __construct(FieldValueObject $formField)
30 {
31 $this->formField = $formField;
32 }
33
34 /**
35 * Get the ID of the form to which this field belongs
36 *
37 * @return int The form ID.
38 */
39 public function getFormId(): int
40 {
41 return $this->formField->getFormId();
42 }
43
44 /**
45 * Set the ID of the form to which this field belongs.
46 *
47 * @param int $formId The form ID to set.
48 */
49 public function setFormId(int $formId): void
50 {
51 $this->formField->formId = $formId;
52 }
53
54 /**
55 * Get ID of the form field.
56 *
57 * @return int The form field id.
58 */
59 public function getId(): int
60 {
61 return $this->formField->getId();
62 }
63
64 /**
65 * Set the ID of the form field.
66 *
67 * @param int $id The ID to set.
68 */
69 public function setId(int $id): void
70 {
71 $this->formField->id = $id;
72 }
73
74 /**
75 * Get the index of the form field.
76 *
77 * @return int The index of the form field.
78 */
79 public function getIndex(): int
80 {
81 return $this->formField->getIndex();
82 }
83
84 /**
85 * Set the index of the form field.
86 *
87 * @param int $index The index to set.
88 */
89 public function setIndex(int $index): void
90 {
91 $this->formField->fieldIndex = $index;
92 }
93
94 /**
95 * Get the type of the form field.
96 *
97 * @return string The type of the form field.
98 */
99 public function getType(): string
100 {
101 return $this->formField->getType();
102 }
103
104 /**
105 * Set the type of the form field.
106 *
107 * @param string $type The type to set.
108 */
109 public function setType(string $type): void
110 {
111 $this->formField->type = $type;
112 }
113
114 /**
115 * Get the label of the form field.
116 *
117 * @return string The label of the form field.
118 */
119 public function getLabel(): string
120 {
121 return $this->formField->getLabel();
122 }
123
124 /**
125 * Set the label of the form field.
126 *
127 * @param string $label The label to set.
128 */
129 public function setLabel(string $label): void
130 {
131 $this->formField->label = $label;
132 }
133
134 /**
135 * Get the default value of the form field.
136 *
137 * @return string The default value of the form field.
138 */
139 public function getDefaultValue(): string
140 {
141 return $this->formField->getDefaultValue();
142 }
143
144 /**
145 * Set the default value of the form field.
146 *
147 * @param string $defaultValue The default value to set.
148 */
149 public function setDefaultValue(string $defaultValue): void
150 {
151 $this->formField->defaultValue = $defaultValue;
152 }
153
154 /**
155 * Check if the form field is required.
156 *
157 * @return bool True if the form field is required, false otherwise.
158 */
159 public function isRequired(): bool
160 {
161 return $this->formField->isRequired();
162 }
163
164 /**
165 * Set the required status of the form field.
166 *
167 * @param bool $required The required status to set.
168 */
169 public function setRequired(bool $required): void
170 {
171 $this->formField->required = $required;
172 }
173
174 /**
175 * Get the placeholder of the form field.
176 *
177 * @return string The placeholder of the form field.
178 */
179 public function getPlaceholder(): string
180 {
181 return $this->formField->getPlaceholder();
182 }
183
184 /**
185 * Set the placeholder of the form field.
186 *
187 * @param string $placeholder The placeholder to set.
188 */
189 public function setPlaceholder(string $placeholder): void
190 {
191 $this->formField->placeholder = $placeholder;
192 }
193
194 /**
195 * Get the position of the form field.
196 *
197 * @return int The position of the form field.
198 */
199 public function getPosition(): int
200 {
201 return $this->formField->getPosition();
202 }
203
204 /**
205 * Set the position of the form field.
206 *
207 * @param int $position The position to set.
208 */
209 public function setPosition(int $position): void
210 {
211 $this->formField->position = $position;
212 }
213
214 /**
215 * Check if the field label should be hidden.
216 *
217 * @return bool True if the label should be hidden, false otherwise.
218 */
219 public function isLabelHidden(): bool
220 {
221 return $this->formField->isLabelHidden();
222 }
223
224 /**
225 * Set the hideLabel setting.
226 *
227 * @param bool $hideLabel The hideLabel setting to set.
228 */
229 public function setHideLabel(bool $hideLabel): void
230 {
231 $this->formField->setHideLabel($hideLabel);
232 }
233
234 /**
235 * Check if the field is read-only.
236 *
237 * @return bool True if the field is read-only, false otherwise.
238 */
239 public function isReadOnly(): bool
240 {
241 return $this->formField->isReadOnly();
242 }
243
244 /**
245 * Set the readOnly setting.
246 *
247 * @param bool $readOnly The readOnly setting to set.
248 */
249 public function setReadOnly(bool $readOnly): void
250 {
251 $this->formField->setReadOnly($readOnly);
252 }
253
254 /**
255 * Get the field description.
256 *
257 * @return string The description of the form field.
258 */
259 public function getDescription(): string
260 {
261 return $this->formField->getDescription();
262 }
263
264 /**
265 * Set the description setting.
266 *
267 * @param string $description The description setting to set.
268 */
269 public function setDescription(string $description): void
270 {
271 $this->formField->setDescription($description);
272 }
273
274 /**
275 * Get the field required message.
276 *
277 * @return string The required message of the form field.
278 */
279 public function getRequiredMessage(): string
280 {
281 return $this->formField->getRequiredMessage();
282 }
283
284 /**
285 * Set the required message setting.
286 *
287 * @param string $requiredMessage The required message setting to set.
288 */
289 public function setRequiredMessage(string $requiredMessage): void
290 {
291 $this->formField->setRequiredMessage($requiredMessage);
292 }
293
294 /**
295 * Get the field CSS classes.
296 *
297 * @return string The CSS classes of the form field.
298 */
299 public function getCssClasses(): string
300 {
301 return $this->formField->getCssClasses();
302 }
303
304 /**
305 * Set the CSS classes setting.
306 *
307 * @param string $cssClasses The CSS classes setting to set.
308 */
309 public function setCssClasses(string $cssClasses): void
310 {
311 $this->formField->setCssClasses($cssClasses);
312 }
313
314 /**
315 * Convert the form field entity to an array.
316 *
317 * @return array<string, mixed> The form field entity as an array.
318 */
319 public function toArray(): array
320 {
321 return [
322 'id' => $this->getId(),
323 'formId' => $this->getFormId(),
324 'fieldIndex' => $this->getIndex(),
325 'type' => $this->getType(),
326 'label' => $this->getLabel(),
327 'defaultValue' => $this->getDefaultValue(),
328 'required' => $this->isRequired(),
329 'placeholder' => $this->getPlaceholder(),
330 'position' => $this->getPosition(),
331 'hideLabel' => $this->isLabelHidden(),
332 'readOnly' => $this->isReadOnly(),
333 'description' => $this->getDescription(),
334 'requiredMessage' => $this->getRequiredMessage(),
335 'cssClasses' => $this->getCssClasses(),
336 ];
337 }
338 }
339