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 +64 -3 1.1 → 1.5.1 View file →
@@ -2,8 +2,9 @@
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 9
9 10 /**
@@ -9,8 +10,9 @@
9 10 /**
10 11 * Class Form - Core form value object with composed metadata and settings
11 12 *
12 13 * @package IvyForms\ValueObjects\Form
14 + * @SuppressWarnings(PHPMD.TooManyFields)
13 15 */
14 16 final class Form
15 17 {
16 18 /**
@@ -67,8 +69,21 @@
67 69 */
68 70 public array $formActionButtons;
69 71
70 72 /**
73 + * Lowercase presentation type (classic, conversational, or plugin-defined via
74 + * ivyforms/form/allowed_form_types). Always matches Sanitizer::sanitizeFormType().
75 + *
76 + * @var string
77 + */
78 + public string $formType;
79 +
80 + /**
81 + * @var PaymentSettings
82 + */
83 + public PaymentSettings $paymentSettings;
84 +
85 + /**
71 86 * Form constructor.
72 87 *
73 88 * @param int $id
74 89 * @param string $name
@@ -80,8 +95,10 @@
80 95 * @param array<int, array<string, mixed>>|null $pages
81 96 * @param array<string, mixed>|null $progressIndicator
82 97 * @param StyleSettings|null $styleSettings
83 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
84 101 * @SuppressWarnings("ExcessiveParameterList")
85 102 * @throws ValidationException
86 103 */
87 104 public function __construct(
@@ -94,9 +111,11 @@
94 111 ?IntegrationSettings $integrationSettings = null,
95 112 ?array $pages = null,
96 113 ?array $progressIndicator = null,
97 114 ?StyleSettings $styleSettings = null,
98 - ?array $formActionButtons = null
115 + ?array $formActionButtons = null,
116 + string $formType = Sanitizer::FORM_TYPE_CLASSIC,
117 + $paymentSettings = null
99 118 ) {
100 119 $this->id = $this->validateId($id);
101 120 $this->name = $this->validateString($name, 255, 'name');
102 121 $this->description = $this->validateString($description, 1000, 'description');
@@ -111,12 +130,26 @@
111 130 'label' => BackendStrings::getCommonStrings()['submit'],
112 131 'position' => 'default',
113 132 ],
114 133 ];
115 - $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);
116 140 }
117 141
118 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 + /**
119 152 * Validates the ID.
120 153 *
121 154 * @param int $id
122 155 *
@@ -178,8 +211,24 @@
178 211 return $this->name;
179 212 }
180 213
181 214 /**
215 + * @return string
216 + */
217 + public function getFormType(): string
218 + {
219 + return $this->formType;
220 + }
221 +
222 + /**
223 + * @param string $formType
224 + */
225 + public function setFormType(string $formType): void
226 + {
227 + $this->formType = $this->normalizeStoredFormType($formType);
228 + }
229 +
230 + /**
182 231 * Get the form description.
183 232 *
184 233 * @return string
185 234 */
@@ -215,8 +264,18 @@
215 264 {
216 265 $this->integrationSettings = $settings;
217 266 }
218 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 +
219 278 /**
220 279 * Get style settings value object.
221 280 *
222 281 * @return StyleSettings|null
@@ -255,8 +314,9 @@
255 314 [
256 315 'id' => $this->getId(),
257 316 'name' => $this->getName(),
258 317 'description' => $this->getDescription(),
318 + 'formType' => $this->getFormType(),
259 319 'fields' => $this->getFields(),
260 320 'pages' => $this->pages,
261 321 'progressIndicator' => $this->progressIndicator,
262 322 'formActionButtons' => $this->formActionButtons,
@@ -263,8 +323,9 @@
263 323 ],
264 324 $this->metadata->toArray(),
265 325 $this->settings->toArray(),
266 326 $integrationPayload,
267 - $stylePayload
327 + $stylePayload,
328 + $this->getPaymentSettings()->toArray()
268 329 );
269 330 }
270 331 }