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/Field/FieldService.php +5 -58 1.0 → 1.5.1 View file →
@@ -9,9 +9,8 @@
9 9 use IvyForms\Factory\Field\FieldFactory;
10 10 use IvyForms\Factory\FieldOptions\FieldOptionsFactory;
11 11 use IvyForms\Repository\Field\FieldRepositoryInterface;
12 12 use IvyForms\Repository\FieldOptions\FieldOptionsRepositoryInterface;
13 -use IvyForms\Repository\EntryField\EntryFieldRepositoryInterface;
14 13 use IvyForms\Services\Translations\BackendStrings;
15 14 use IvyForms\Common\Helpers\FieldHelper;
16 15 use IvyForms\Services\Media\ImageService;
17 16
@@ -21,9 +20,8 @@
21 20 class FieldService
22 21 {
23 22 private FieldRepositoryInterface $fieldRepository;
24 23 private FieldOptionsRepositoryInterface $fieldOptionsRepository;
25 - private EntryFieldRepositoryInterface $entryFieldRepository;
26 24 private ImageService $imageService;
27 25
28 26 // Constructor injection for repositories only via PHP-DI
29 27 public function __construct(
@@ -28,14 +26,12 @@
28 26 // Constructor injection for repositories only via PHP-DI
29 27 public function __construct(
30 28 FieldRepositoryInterface $fieldRepository,
31 29 FieldOptionsRepositoryInterface $fieldOptionsRepository,
32 - EntryFieldRepositoryInterface $entryFieldRepository,
33 30 ImageService $imageService
34 31 ) {
35 32 $this->fieldRepository = $fieldRepository;
36 33 $this->fieldOptionsRepository = $fieldOptionsRepository;
37 - $this->entryFieldRepository = $entryFieldRepository;
38 34 $this->imageService = $imageService;
39 35 }
40 36
41 37 /**
@@ -194,10 +190,11 @@
194 190 foreach ($fields as $fieldData) {
195 191 $fieldData['formId'] = $fieldData['formId'] ?? $formId;
196 192 // Resolve parentId using fieldIndex if available
197 193 FieldHelper::resolveParentId($fieldData, $parentMap);
198 - // Process htmlContent to upload base64 images
194 + // Process htmlContent / rich text default values to upload base64 images
199 195 FieldHelper::processFieldHtmlContent($fieldData, $this->imageService);
196 + FieldHelper::processRichTextDefaultValue($fieldData, $this->imageService);
200 197 $field = FieldFactory::create($fieldData);
201 198 $fieldId = $this->addField($field);
202 199 // If this is a parent field (no parentId), store its DB id in the map
203 200 if ($field->getParentId() === null) {
@@ -227,10 +224,11 @@
227 224 $parentMap = [];
228 225 foreach ($fields as $fieldData) {
229 226 $fieldData['formId'] = $fieldData['formId'] ?? $formId;
230 227 FieldHelper::resolveParentId($fieldData, $parentMap);
231 - // Process htmlContent to upload base64 images
228 + // Process htmlContent / rich text default values to upload base64 images
232 229 FieldHelper::processFieldHtmlContent($fieldData, $this->imageService);
230 + FieldHelper::processRichTextDefaultValue($fieldData, $this->imageService);
233 231 $field = FieldFactory::create($fieldData);
234 232 $fieldId = $field->getId();
235 233
236 234 if ($fieldId === 0) { // new field
@@ -324,42 +322,8 @@
324 322 }
325 323 }
326 324
327 325 /**
328 - * Check for duplicate field values in submission.
329 - * @param Field[] $formFields
330 - * @param array<string,mixed> $submissionData
331 - * @param int $formId
332 - * @return array{0: bool, 1: array<int|string,bool>}
333 - */
334 - public function checkDuplicateFieldValues(
335 - array $formFields,
336 - array $submissionData,
337 - int $formId
338 - ): array {
339 - $duplicateErrors = [];
340 - $isDuplicate = false;
341 - $fieldValues = [];
342 -
343 - foreach ($formFields as $field) {
344 - $fid = $field->getId();
345 - $fidStr = (string)$fid;
346 - if (isset($submissionData[$fidStr])) {
347 - $fieldValues[$fidStr] = $submissionData[$fidStr];
348 - }
349 - if ($field->getFieldAdvancedSettings()->isNoDuplicates() && !empty($fieldValues[$fidStr])) {
350 - $val = $fieldValues[$fidStr];
351 - if ($this->entryFieldRepository->checkDuplicateValue($formId, $fid, $val)) {
352 - $duplicateErrors[$fidStr] = true;
353 - $isDuplicate = true;
354 - }
355 - }
356 - }
357 -
358 - return [$isDuplicate, $duplicateErrors];
359 - }
360 -
361 - /**
362 326 * Validate that all fields have allowed types.
363 327 * @param Field[]|mixed[] $formFields
364 328 * @throws InvalidArgumentException
365 329 */
@@ -364,24 +328,7 @@
364 328 * @throws InvalidArgumentException
365 329 */
366 330 public function validateFieldsType(array $formFields): void
367 331 {
368 - // Validate field types
369 - $allowedTypes = FieldType::getAllowedTypes();
370 - foreach ($formFields as $field) {
371 - // Check if field is an instance of Field or array
372 - $fieldType = $field instanceof Field ? $field->getType() : ($field['type'] ?? null);
373 -
374 - if ($fieldType === null) {
375 - throw new InvalidArgumentException(
376 - BackendStrings::getExceptionStrings()['invalid_field_type'] . ' (type not found)'
377 - );
378 - }
379 -
380 - if (!in_array($fieldType, $allowedTypes, true)) {
381 - throw new InvalidArgumentException(
382 - BackendStrings::getExceptionStrings()['invalid_field_type'] . ' ' . $fieldType
383 - );
384 - }
385 - }
332 + FieldType::validateFields($formFields);
386 333 }
387 334 }