PluginProbe
The Innovative Form Builder – IvyForms / 0.4
The Innovative Form Builder – IvyForms v0.4
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.4, at backend/src/Entity/Field/Field.php

299 lines 7.3 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 use IvyForms\Entity\Field\FieldGeneralSettings;
12 use IvyForms\Entity\Field\FieldAdvancedSettings;
13
14 /**
15 * Class Field
16 *
17 * @package IvyForms\Entity\Field
18 */
19 class Field
20 {
21 /**
22 * @var FieldGeneralSettings
23 */
24 private FieldGeneralSettings $fieldGeneralSettings;
25 /**
26 * @var FieldAdvancedSettings
27 */
28 private FieldAdvancedSettings $fieldAdvancedSettings;
29 /**
30 * @var FieldValueObject
31 */
32 private FieldValueObject $formField;
33
34 /**
35 * Field constructor.
36 *
37 * @param FieldValueObject $formField The form field object.
38 */
39 public function __construct(FieldValueObject $formField)
40 {
41 $this->formField = $formField;
42 $this->fieldGeneralSettings = new FieldGeneralSettings($formField->getGeneralSettings());
43 $this->fieldAdvancedSettings = new FieldAdvancedSettings($formField->getAdvancedSettings());
44 }
45
46 /**
47 * Get the ID of the form to which this field belongs
48 *
49 * @return int The form ID.
50 */
51 public function getFormId(): int
52 {
53 return $this->formField->getFormId();
54 }
55
56 /**
57 * Set the ID of the form to which this field belongs.
58 *
59 * @param int $formId The form ID to set.
60 */
61 public function setFormId(int $formId): void
62 {
63 $this->formField->formId = $formId;
64 }
65
66 /**
67 * Get ID of the form field.
68 *
69 * @return int The form field id.
70 */
71 public function getId(): int
72 {
73 return $this->formField->getId();
74 }
75
76 /**
77 * Set the ID of the form field.
78 *
79 * @param int $id The ID to set.
80 */
81 public function setId(int $id): void
82 {
83 $this->formField->id = $id;
84 }
85
86 /**
87 * Get the index of the form field.
88 *
89 * @return int The index of the form field.
90 */
91 public function getIndex(): int
92 {
93 return $this->formField->getIndex();
94 }
95
96 /**
97 * Set the index of the form field.
98 *
99 * @param int $index The index to set.
100 */
101 public function setIndex(int $index): void
102 {
103 $this->formField->fieldIndex = $index;
104 }
105
106 /**
107 * Get the type of the form field.
108 *
109 * @return string The type of the form field.
110 */
111 public function getType(): string
112 {
113 return $this->formField->getType();
114 }
115
116 /**
117 * Set the type of the form field.
118 *
119 * @param string $type The type to set.
120 */
121 public function setType(string $type): void
122 {
123 $this->formField->type = $type;
124 }
125
126 /**
127 * Get the position of the form field.
128 *
129 * @return int The position of the form field.
130 */
131 public function getPosition(): int
132 {
133 return $this->formField->getPosition();
134 }
135
136 /**
137 * Set the position of the form field.
138 *
139 * @param int $position The position to set.
140 */
141 public function setPosition(int $position): void
142 {
143 $this->formField->position = $position;
144 }
145
146 /**
147 * Get the parent field ID.
148 *
149 * @return int|null The parent field ID.
150 */
151 public function getParentId(): ?int
152 {
153 return $this->formField->getParentId();
154 }
155
156 /**
157 * Set the parent field ID.
158 *
159 * @param int|null $parentId The parent field ID to set.
160 */
161 public function setParentId(?int $parentId): void
162 {
163 $this->formField->parentId = $parentId;
164 }
165
166 /**
167 * Check if the confirm field feature is enabled.
168 *
169 * @return bool True if the confirm field feature is enabled, false otherwise.
170 */
171 public function isConfirmFieldEnabled(): bool
172 {
173 return $this->formField->isConfirmFieldEnabled();
174 }
175
176 /**
177 * Get the label for the confirm field field.
178 *
179 * @return string The label for the confirm field field.
180 */
181 public function getConfirmFieldLabel(): string
182 {
183 return $this->formField->getConfirmFieldLabel();
184 }
185
186 /**
187 * Get the placeholder for the confirm field field.
188 *
189 * @return string The placeholder for the confirm field field.
190 */
191 public function getConfirmFieldPlaceholder(): string
192 {
193 return $this->formField->getConfirmFieldPlaceholder();
194 }
195
196 /**
197 * Check if the confirm field label should be hidden.
198 *
199 * @return bool True if the confirm label should be hidden, false otherwise.
200 */
201 public function isConfirmFieldHideLabel(): bool
202 {
203 return $this->formField->isConfirmFieldHideLabel();
204 }
205
206 /**
207 * Set the enabled status of the confirm field feature.
208 *
209 * @param bool $enabled The enabled status to set.
210 */
211 public function setConfirmFieldEnabled(bool $enabled): void
212 {
213 $this->formField->setConfirmFieldEnabled($enabled);
214 }
215
216 /**
217 * Set the label for the confirm field.
218 *
219 * @param string $label The label to set.
220 */
221 public function setConfirmFieldLabel(string $label): void
222 {
223 $this->formField->setConfirmFieldLabel($label);
224 }
225
226 /**
227 * Set the placeholder for the confirm field.
228 *
229 * @param string $ph The placeholder to set.
230 */
231 public function setConfirmFieldPlaceholder(string $ph): void
232 {
233 $this->formField->setConfirmFieldPlaceholder($ph);
234 }
235
236 /**
237 * Set the hideLabel setting for the confirm field.
238 *
239 * @param bool $hide The hideLabel setting to set.
240 */
241 public function setConfirmFieldHideLabel(bool $hide): void
242 {
243 $this->formField->setConfirmFieldHideLabel($hide);
244 }
245
246 /**
247 * Set the number of rows (for textarea fields).
248 *
249 * @param int $rows
250 */
251 public function setRows(int $rows): void
252 {
253 $this->formField->setRows($rows);
254 }
255
256 /**
257 * Get the FieldGeneralSettings entity.
258 */
259 public function getFieldGeneralSettings(): FieldGeneralSettings
260 {
261 return $this->fieldGeneralSettings;
262 }
263
264 /**
265 * Get the FieldAdvancedSettings entity.
266 */
267 public function getFieldAdvancedSettings(): FieldAdvancedSettings
268 {
269 return $this->fieldAdvancedSettings;
270 }
271
272
273 /**
274 * Convert the form field entity to an array.
275 *
276 * @return array<string, mixed> The form field entity as an array.
277 */
278 public function toArray(): array
279 {
280 return array_merge(
281 [
282 'id' => $this->getId(),
283 'formId' => $this->getFormId(),
284 'fieldIndex' => $this->getIndex(),
285 'type' => $this->getType(),
286 'position' => $this->getPosition(),
287 'parentId' => $this->getParentId(),
288 'rows' => $this->formField->getRows(),
289 'confirmFieldEnabled' => $this->isConfirmFieldEnabled(),
290 'confirmFieldLabel' => $this->getConfirmFieldLabel(),
291 'confirmFieldPlaceholder' => $this->getConfirmFieldPlaceholder(),
292 'confirmFieldHideLabel' => $this->isConfirmFieldHideLabel(),
293 ],
294 $this->getFieldGeneralSettings()->toArray(),
295 $this->getFieldAdvancedSettings()->toArray()
296 );
297 }
298 }
299