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/Services/Entry/Managers/EntryFieldManager.php +40 -5 1.1.1 → 1.5 View file →
@@ -4,8 +4,9 @@
4 4
5 5 use IvyForms\Common\Exceptions\ValidationException;
6 6 use IvyForms\Common\Helpers\EntryHelper;
7 7 use IvyForms\Common\Helpers\FieldHelper;
8 +use IvyForms\Entity\EntryField\EntryField;
8 9 use IvyForms\Factory\EntryField\EntryFieldFactory;
9 10 use IvyForms\Repository\Entry\EntryRepositoryInterface;
10 11 use IvyForms\Repository\EntryField\EntryFieldRepositoryInterface;
11 12
@@ -50,16 +51,27 @@
50 51 * @param int $fieldId
51 52 * @param string $value
52 53 * @return bool
53 54 */
54 - public function checkDuplicateValue(int $formId, int $fieldId, string $value): bool
55 - {
56 - return $this->entryFieldRepository->checkDuplicateValue($formId, $fieldId, $value);
55 + public function checkDuplicateValue(
56 + int $formId,
57 + int $fieldId,
58 + string $value,
59 + ?int $excludeEntryId = null
60 + ): bool {
61 + return $this->entryFieldRepository->checkDuplicateValue(
62 + $formId,
63 + $fieldId,
64 + $value,
65 + $excludeEntryId
66 + );
57 67 }
58 68
59 69 /**
60 70 * Add entry fields to the repository.
61 71 *
72 + * Resolves all field values in PHP, then persists with a single multi-row INSERT.
73 + *
62 74 * @param array<int, object> $formFields
63 75 * @param int $entryId
64 76 * @param array<mixed> $submissionData
65 77 * @throws ValidationException
@@ -72,8 +84,11 @@
72 84 $submissionData,
73 85 $formFields
74 86 );
75 87
88 + /** @var list<array{entryField: EntryField, field: object}> $created */
89 + $created = [];
90 +
76 91 foreach ($formFields as $field) {
77 92 // Skip security/CAPTCHA fields - their tokens are only needed for verification, not storage
78 93 $fieldType = $field->getType();
79 94 if (FieldHelper::isSecurityField($fieldType)) {
@@ -79,8 +94,14 @@
79 94 if (FieldHelper::isSecurityField($fieldType)) {
80 95 continue;
81 96 }
82 97
98 + /** @var bool $shouldSkip */
99 + $shouldSkip = apply_filters('ivyforms/entry/field/should_skip', false, $field);
100 + if ($shouldSkip) {
101 + continue;
102 + }
103 +
83 104 $value = $this->valueManager->resolveFieldValue(
84 105 $field,
85 106 $submissionData,
86 107 $parentChildrenMap,
@@ -128,11 +149,25 @@
128 149 $field,
129 150 $submissionData
130 151 );
131 152
132 - $entryField = EntryFieldFactory::create($entryFieldData);
153 + $created[] = [
154 + 'entryField' => EntryFieldFactory::create($entryFieldData),
155 + 'field' => $field,
156 + ];
157 + }
133 158
134 - $this->entryFieldRepository->add($entryField);
159 + if ($created === []) {
160 + return;
161 + }
162 +
163 + $this->entryFieldRepository->batchInsert(
164 + array_column($created, 'entryField')
165 + );
166 +
167 + foreach ($created as $item) {
168 + $entryField = $item['entryField'];
169 + $field = $item['field'];
135 170
136 171 /**
137 172 * Action fired after an entry field has been saved to the database.
138 173 * Allows post-processing or logging of entry field creation.