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