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

234 lines 5.1 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 * Convert the form field entity to an array.
216 *
217 * @return array<string, mixed> The form field entity as an array.
218 */
219 public function toArray(): array
220 {
221 return [
222 'id' => $this->getId(),
223 'formId' => $this->getFormId(),
224 'fieldIndex' => $this->getIndex(),
225 'type' => $this->getType(),
226 'label' => $this->getLabel(),
227 'defaultValue' => $this->getDefaultValue(),
228 'required' => $this->isRequired(),
229 'placeholder' => $this->getPlaceholder(),
230 'position' => $this->getPosition(),
231 ];
232 }
233 }
234