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/Services/Form/FormService.php +65 -5 0.4 → 1.5.1 View file →
@@ -1,13 +1,9 @@
1 1 <?php
2 2
3 3 namespace IvyForms\Services\Form;
4 4
5 -// phpcs:disable PSR1.Files.SideEffects
6 -if (!defined('ABSPATH')) {
7 - exit; // Exit if accessed directly
8 -}
9 -
5 +use IvyForms\Common\Exceptions\InvalidArgumentException;
10 6 use IvyForms\Common\Exceptions\NotFoundException;
11 7 use IvyForms\Common\Exceptions\QueryExecutionException;
12 8 use IvyForms\Common\Exceptions\ValidationException;
13 9 use IvyForms\Entity\Form\Form;
@@ -42,8 +38,16 @@
42 38 return $this->formRepository->getAll();
43 39 }
44 40
45 41 /**
42 + * @return list<int>
43 + */
44 + public function getAllFormIds(): array
45 + {
46 + return $this->formRepository->getAllIds();
47 + }
48 +
49 + /**
46 50 * Create a new form.
47 51 *
48 52 * @param Form $formData
49 53 *
@@ -111,8 +115,35 @@
111 115 return [$formId, $form];
112 116 }
113 117
114 118 /**
119 + * Preserve the persisted formType when the caller omits it, so a partial update
120 + * (e.g. settings/name change) cannot silently demote the form's type.
121 + *
122 + * @param array<string,mixed> $rawParams Request payload to be sanitized.
123 + * @param int $formId Form id resolved from the route (URL placeholder).
124 + * @return array<string,mixed>
125 + * @throws NotFoundException
126 + */
127 + public function withPreservedFormType(array $rawParams, int $formId): array
128 + {
129 + if (array_key_exists('formType', $rawParams)) {
130 + return $rawParams;
131 + }
132 +
133 + if ($formId <= 0) {
134 + return $rawParams;
135 + }
136 +
137 + $existing = $this->getFormById($formId);
138 + if (method_exists($existing, 'getFormType')) {
139 + $rawParams['formType'] = $existing->getFormType();
140 + }
141 +
142 + return $rawParams;
143 + }
144 +
145 + /**
115 146 * Update the starred field of a form.
116 147 *
117 148 * @param int $formId
118 149 * @param mixed $value
@@ -145,8 +176,15 @@
145 176 * @return int
146 177 */
147 178 public function deleteForm(int $formId): int
148 179 {
180 + /**
181 + * Fires before a form is deleted.
182 + *
183 + * @param int $formId The ID of the form being deleted.
184 + */
185 + do_action('ivyforms/form/before_delete', $formId);
186 +
149 187 return $this->formRepository->delete($formId);
150 188 }
151 189
152 190 /**
@@ -157,8 +195,17 @@
157 195 * @return int Number of deleted forms
158 196 */
159 197 public function deleteForms(array $formIds): int
160 198 {
199 + foreach ($formIds as $formId) {
200 + /**
201 + * Fires before a form is deleted.
202 + *
203 + * @param int $formId The ID of the form being deleted.
204 + */
205 + do_action('ivyforms/form/before_delete', (int) $formId);
206 + }
207 +
161 208 return $this->formRepository->deleteMany($formIds);
162 209 }
163 210
164 211 /**
@@ -225,6 +272,19 @@
225 272 if ($shouldGetCount) {
226 273 return $this->formRepository->getFilterCount();
227 274 }
228 275 return [];
276 + }
277 +
278 + /**
279 + * Bulk update a column for multiple forms.
280 + *
281 + * @param string $column Column name to update
282 + * @param mixed $value Value to set
283 + * @param array<int> $ids Array of form IDs
284 + * @return int Number of updated forms
285 + */
286 + public function bulkUpdateColumn(string $column, $value, array $ids): int
287 + {
288 + return $this->formRepository->bulkUpdateColumn($column, $value, $ids);
229 289 }
230 290 }