PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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
← All changes | backend/src/ValueObjects/Form/Form.php +110 -152 1.0 → 1.5 View file →
@@ -2,16 +2,17 @@
2 2
3 3 namespace IvyForms\ValueObjects\Form;
4 4
5 5 use IvyForms\Common\Exceptions\ValidationException;
6 +use IvyForms\Common\Sanitizer\Sanitizer;
6 7 use IvyForms\Services\Template\TemplateDefaults;
7 8 use IvyForms\Services\Translations\BackendStrings;
8 -use IvyForms\ValueObjects\Form\IntegrationSettings;
9 9
10 10 /**
11 - * Class Form
11 + * Class Form - Core form value object with composed metadata and settings
12 12 *
13 13 * @package IvyForms\ValueObjects\Form
14 + * @SuppressWarnings(PHPMD.TooManyFields)
14 15 */
15 16 final class Form
16 17 {
17 18 /**
@@ -17,65 +18,70 @@
17 18 /**
18 19 * @var int
19 20 */
20 21 public int $id;
22 +
21 23 /**
22 24 * @var string
23 25 */
24 26 public string $name;
27 +
25 28 /**
26 29 * @var string
27 30 */
28 - public string $author;
31 + public string $description;
32 +
29 33 /**
30 - * @var bool
34 + * @var FormMetadata
31 35 */
32 - public bool $published;
36 + public FormMetadata $metadata;
37 +
33 38 /**
34 - * @var bool
39 + * @var FormSettings
35 40 */
36 - public bool $starred;
41 + public FormSettings $settings;
42 +
37 43 /**
38 - * @var string
39 - */
40 - public string $dateCreated;
41 - /**
42 - * @var string
43 - */
44 - public string $dateEdited;
45 - /**
46 44 * @var array<int, array<string, mixed>>|null
47 45 */
48 46 public ?array $fields;
47 +
49 48 /**
50 - * @var string
49 + * @var IntegrationSettings|null
51 50 */
52 - public string $description;
51 + public ?IntegrationSettings $integrationSettings;
53 52 /**
54 - * @var bool
53 + * @var StyleSettings|null
55 54 */
56 - public bool $showTitle;
55 + public ?StyleSettings $styleSettings;
56 +
57 57 /**
58 - * @var bool
58 + * @var array<int, array<string, mixed>>|null
59 59 */
60 - public bool $showDescription;
60 + public ?array $pages;
61 +
61 62 /**
62 - * @var bool
63 + * @var array<string, mixed>|null
63 64 */
64 - public bool $storeEntries;
65 + public ?array $progressIndicator;
66 +
65 67 /**
66 - * @var IntegrationSettings|null
68 + * @var array<string, mixed>
67 69 */
68 - public ?IntegrationSettings $integrationSettings;
70 + public array $formActionButtons;
71 +
69 72 /**
70 - * @var StyleSettings|null
73 + * Lowercase presentation type (classic, conversational, or plugin-defined via
74 + * ivyforms/form/allowed_form_types). Always matches Sanitizer::sanitizeFormType().
75 + *
76 + * @var string
71 77 */
72 - public ?StyleSettings $styleSettings;
78 + public string $formType;
73 79
74 80 /**
75 - * @var array<string, mixed>
81 + * @var PaymentSettings
76 82 */
77 - public array $formActionButtons;
83 + public PaymentSettings $paymentSettings;
78 84
79 85 /**
80 86 * Form constructor.
81 87 *
@@ -80,60 +86,70 @@
80 86 * Form constructor.
81 87 *
82 88 * @param int $id
83 89 * @param string $name
84 - * @param string $author
85 - * @param bool $starred
86 - * @param bool $published
87 90 * @param string $description
88 - * @param bool $showTitle
89 - * @param bool $showDescription
90 - * @param bool $storeEntries
91 + * @param FormMetadata $metadata
92 + * @param FormSettings $settings
91 93 * @param array<int, array<string, mixed>> $fields
92 94 * @param IntegrationSettings|null $integrationSettings
95 + * @param array<int, array<string, mixed>>|null $pages
96 + * @param array<string, mixed>|null $progressIndicator
93 97 * @param StyleSettings|null $styleSettings
94 98 * @param array<string, mixed>|null $formActionButtons
99 + * @param string $formType presentation type (sanitized to the allowed allowlist)
100 + * @param PaymentSettings|array<string, mixed>|null $paymentSettings
101 + * @SuppressWarnings("ExcessiveParameterList")
95 102 * @throws ValidationException
96 - * @SuppressWarnings("ExcessiveParameterList")
97 103 */
98 104 public function __construct(
99 105 int $id,
100 106 string $name,
101 - string $author,
102 - bool $starred,
103 - bool $published,
104 107 string $description,
105 - bool $showTitle,
106 - bool $showDescription,
107 - bool $storeEntries,
108 + FormMetadata $metadata,
109 + FormSettings $settings,
108 110 array $fields = [],
109 - IntegrationSettings $integrationSettings = null,
111 + ?IntegrationSettings $integrationSettings = null,
112 + ?array $pages = null,
113 + ?array $progressIndicator = null,
110 114 ?StyleSettings $styleSettings = null,
111 - ?array $formActionButtons = null
115 + ?array $formActionButtons = null,
116 + string $formType = Sanitizer::FORM_TYPE_CLASSIC,
117 + $paymentSettings = null
112 118 ) {
113 - $this->id = $this->validateId($id);
114 - $this->name = $this->validateString($name, 255, 'name');
115 - $this->author = $this->validateString($author, 1000, 'author');
116 - $this->starred = $this->validateBool($starred);
117 - $this->published = $this->validateBool($published);
118 - $this->dateCreated = gmdate('Y-m-d H:i:s');
119 - $this->dateEdited = gmdate('Y-m-d H:i:s');
120 - $this->fields = $fields;
121 - $this->description = $this->validateString($description, 1000, 'description');
122 - $this->showTitle = $this->validateBool($showTitle);
123 - $this->showDescription = $this->validateBool($showDescription);
124 - $this->storeEntries = $this->validateBool($storeEntries);
125 - $this->integrationSettings = $integrationSettings;
119 + $this->id = $this->validateId($id);
120 + $this->name = $this->validateString($name, 255, 'name');
121 + $this->description = $this->validateString($description, 1000, 'description');
122 + $this->metadata = $metadata;
123 + $this->settings = $settings;
124 + $this->fields = $fields;
125 + $this->integrationSettings = $integrationSettings;
126 + $this->pages = $pages;
127 + $this->progressIndicator = $progressIndicator;
126 128 $this->formActionButtons = $formActionButtons ?? [
127 129 'submitButtonSettings' => [
128 - 'label' => BackendStrings::getCommonStrings()['submit'],
129 - 'position' => 'default'
130 - ]
130 + 'label' => BackendStrings::getCommonStrings()['submit'],
131 + 'position' => 'default',
132 + ],
131 133 ];
132 - $this->styleSettings = $styleSettings;
134 + $this->styleSettings = $styleSettings;
135 + $this->formType = $this->normalizeStoredFormType($formType);
136 +
137 + $this->paymentSettings = $paymentSettings instanceof PaymentSettings
138 + ? $paymentSettings
139 + : new PaymentSettings(is_array($paymentSettings) ? $paymentSettings : null);
133 140 }
134 141
135 142 /**
143 + * @param string $formType
144 + * @return string
145 + */
146 + private function normalizeStoredFormType(string $formType): string
147 + {
148 + return Sanitizer::sanitizeFormType($formType);
149 + }
150 +
151 + /**
136 152 * Validates the ID.
137 153 *
138 154 * @param int $id
139 155 *
@@ -173,19 +189,8 @@
173 189 }
174 190 return $value;
175 191 }
176 192
177 - /**
178 - * Validates a boolean field.
179 - *
180 - * @param bool $value
181 - *
182 - * @return bool
183 - */
184 - private function validateBool(bool $value): bool
185 - {
186 - return $value;
187 - }
188 193
189 194 /**
190 195 * Get the form ID.
191 196 *
@@ -206,54 +211,34 @@
206 211 return $this->name;
207 212 }
208 213
209 214 /**
210 - * Get the form author.
211 - *
212 215 * @return string
213 216 */
214 - public function getAuthor(): string
217 + public function getFormType(): string
215 218 {
216 - return $this->author;
219 + return $this->formType;
217 220 }
218 221
219 222 /**
220 - * Get the form starred status.
221 - *
222 - * @return bool
223 + * @param string $formType
223 224 */
224 - public function isStarred(): bool
225 + public function setFormType(string $formType): void
225 226 {
226 - return $this->starred;
227 + $this->formType = $this->normalizeStoredFormType($formType);
227 228 }
229 +
228 230 /**
229 - * Get the form published status.
231 + * Get the form description.
230 232 *
231 - * @return bool
232 - */
233 - public function isPublished(): bool
234 - {
235 - return $this->published;
236 - }
237 - /**
238 - * Get the date of form creation.
239 - *
240 233 * @return string
241 234 */
242 - public function getDateCreated(): string
235 + public function getDescription(): string
243 236 {
244 - return $this->dateCreated;
237 + return $this->description;
245 238 }
239 +
246 240 /**
247 - * Get the form date edited.
248 - *
249 - * @return string
250 - */
251 - public function getDateEdited(): string
252 - {
253 - return $this->dateEdited;
254 - }
255 - /**
256 241 * Get the form fields.
257 242 *
258 243 * @return array<int, array<string, mixed>>|null
259 244 */
@@ -260,37 +245,11 @@
260 245 public function getFields(): ?array
261 246 {
262 247 return $this->fields;
263 248 }
264 - /**
265 - * Get the form description.
266 - *
267 - * @return string
268 - */
269 - public function getDescription(): string
270 - {
271 - return $this->description;
272 - }
273 - /**
274 - * Get the show description of the form.
275 - *
276 - * @return bool The form show description status.
277 - */
278 - public function isDescriptionVisible(): bool
279 - {
280 - return $this->showDescription;
281 - }
282 - /**
283 - * Get the form store entries' status.
284 - * @return bool
285 - */
286 - public function isStoreEntries(): bool
287 - {
288 - return $this->storeEntries;
289 - }
290 249
291 250 /**
292 - * Get integration settings.
251 + * Get the integration settings.
293 252 * @return IntegrationSettings|null
294 253 */
295 254 public function getIntegrationSettings(): ?IntegrationSettings
296 255 {
@@ -305,8 +264,18 @@
305 264 {
306 265 $this->integrationSettings = $settings;
307 266 }
308 267
268 + public function getPaymentSettings(): PaymentSettings
269 + {
270 + return $this->paymentSettings;
271 + }
272 +
273 + public function setPaymentSettings(PaymentSettings $paymentSettings): void
274 + {
275 + $this->paymentSettings = $paymentSettings;
276 + }
277 +
309 278 /**
310 279 * Get style settings value object.
311 280 *
312 281 * @return StyleSettings|null
@@ -326,18 +295,8 @@
326 295 $this->styleSettings = $settings;
327 296 }
328 297
329 298 /**
330 - * Get the show title of the form.
331 - *
332 - * @return bool The form show title status.
333 - */
334 - public function isTitleVisible(): bool
335 - {
336 - return $this->showTitle;
337 - }
338 -
339 - /**
340 299 * Convert the form to an array.
341 300 *
342 301 * @return array<string, mixed>
343 302 */
@@ -352,22 +311,21 @@
352 311 : ['styleSettings' => TemplateDefaults::getDefaultFormStylesSafe()];
353 312
354 313 return array_merge(
355 314 [
356 - 'id' => $this->getId(),
357 - 'name' => $this->getName(),
358 - 'author' => $this->getAuthor(),
359 - 'starred' => $this->isStarred(),
360 - 'published' => $this->isPublished(),
361 - 'dateCreated' => $this->getDateCreated(),
362 - 'dateEdited' => $this->getDateEdited(),
363 - 'fields' => $this->getFields(),
364 - 'description' => $this->getDescription(),
365 - 'showTitle' => $this->isTitleVisible(),
366 - 'showDescription' => $this->isDescriptionVisible(),
367 - 'storeEntries' => $this->isStoreEntries(),
315 + 'id' => $this->getId(),
316 + 'name' => $this->getName(),
317 + 'description' => $this->getDescription(),
318 + 'formType' => $this->getFormType(),
319 + 'fields' => $this->getFields(),
320 + 'pages' => $this->pages,
321 + 'progressIndicator' => $this->progressIndicator,
322 + 'formActionButtons' => $this->formActionButtons,
368 323 ],
324 + $this->metadata->toArray(),
325 + $this->settings->toArray(),
369 326 $integrationPayload,
370 - $stylePayload
327 + $stylePayload,
328 + $this->getPaymentSettings()->toArray()
371 329 );
372 330 }
373 331 }