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/EntryFieldValueManager.php +98 -10 0.9.1 → 1.5 View file →
@@ -6,9 +6,10 @@
6 6 if (!defined('ABSPATH')) {
7 7 exit; // Exit if accessed directly
8 8 }
9 9
10 -use IvyForms\Common\Helpers\DateTimeHelper\DateTimeHelper;
10 +use IvyForms\Common\Helpers\DateTimeHelper\DateHelper;
11 +use IvyForms\Common\Helpers\DateTimeHelper\TimeHelper;
11 12 use IvyForms\Common\Helpers\EntryHelper;
12 13 use IvyForms\Services\Field\FieldService;
13 14
14 15 /**
@@ -47,9 +48,9 @@
47 48 $field = $fieldsById[$fieldId];
48 49 $fieldType = strtolower($field->getType());
49 50 $value = $entryField['fieldValue'];
50 51
51 - $entryField['fieldValue'] = $this->formatFieldValue($fieldType, $value, $skipFormatting);
52 + $entryField['fieldValue'] = $this->formatFieldValue($fieldType, $value, $skipFormatting, $field);
52 53 }
53 54
54 55 return $entryFields;
55 56 }
@@ -125,20 +126,87 @@
125 126 if ($customValue !== null) {
126 127 return $customValue;
127 128 }
128 129
129 - if (in_array($fieldType, ['name', 'address'], true) && ($parentId === null || $parentId === 0)) {
130 - return $this->getCompoundFieldValue($fieldId, $parentChildrenMap, $parentSubfieldKeys, $submissionData);
130 + return $this->resolveByType(
131 + $fieldType,
132 + $fieldId,
133 + $parentId,
134 + $submissionData,
135 + $parentChildrenMap,
136 + $parentSubfieldKeys
137 + );
138 + }
139 +
140 + /**
141 + * Resolve value based on field type.
142 + *
143 + * @param string $fieldType
144 + * @param int $fieldId
145 + * @param int|null $parentId
146 + * @param array<mixed> $submissionData
147 + * @param array<int, array<int>> $parentChildrenMap
148 + * @param array<int, string|null> $parentSubfieldKeys
149 + * @return mixed
150 + */
151 + private function resolveByType(
152 + string $fieldType,
153 + int $fieldId,
154 + ?int $parentId,
155 + array $submissionData,
156 + array $parentChildrenMap,
157 + array $parentSubfieldKeys
158 + ) {
159 + $isParent = $parentId === null || $parentId === 0;
160 +
161 + if ($isParent) {
162 + /**
163 + * Filters the resolved value for a parent field before compound resolution.
164 + * Allows Pro field types (e.g. likert) to resolve parent values without
165 + * hardcoding field types in Lite.
166 + *
167 + * @since 0.1.0
168 + *
169 + * @param mixed|null $value The resolved value (null to continue with default processing).
170 + * @param string $fieldType The field type.
171 + * @param int $fieldId The parent field ID.
172 + * @param mixed[] $parentChildrenMap Map of parent to children field relationships.
173 + * @param mixed[] $parentSubfieldKeys Map of parent subfield keys.
174 + * @param mixed[] $submissionData The submission data array.
175 + * @return mixed The resolved parent field value or null to continue default processing.
176 + */
177 + $parentValue = apply_filters(
178 + 'ivyforms/entry/resolve_parent_field_value',
179 + null,
180 + $fieldType,
181 + $fieldId,
182 + $parentChildrenMap,
183 + $parentSubfieldKeys,
184 + $submissionData
185 + );
186 +
187 + if ($parentValue !== null) {
188 + return $parentValue;
189 + }
131 190 }
132 191
192 + if (in_array($fieldType, ['name', 'address'], true) && $isParent) {
193 + return $this->resolveParentFieldValue(
194 + $fieldId,
195 + $parentChildrenMap,
196 + $parentSubfieldKeys,
197 + $submissionData
198 + );
199 + }
200 +
133 201 if ($fieldType === 'time') {
134 202 $value = EntryHelper::getDefaultFieldValue($fieldId, $submissionData);
135 - return DateTimeHelper::normalizeTimeValue($value);
203 + return TimeHelper::normalizeTimeValue($value);
136 204 }
137 205
138 206 if ($fieldType === 'date') {
139 207 $value = EntryHelper::getDefaultFieldValue($fieldId, $submissionData);
140 - return DateTimeHelper::normalizeDateValue($value);
208 + return DateHelper::normalizeDateValue($value);
141 209 }
142 210
143 211 return EntryHelper::getDefaultFieldValue($fieldId, $submissionData);
144 212 }
@@ -143,8 +211,26 @@
143 211 return EntryHelper::getDefaultFieldValue($fieldId, $submissionData);
144 212 }
145 213
146 214 /**
215 + * Resolve value for a parent field (name, address).
216 + *
217 + * @param int $fieldId
218 + * @param array<int, array<int>> $parentChildrenMap
219 + * @param array<int, string|null> $parentSubfieldKeys
220 + * @param array<int|string, mixed> $submissionData
221 + * @return string
222 + */
223 + private function resolveParentFieldValue(
224 + int $fieldId,
225 + array $parentChildrenMap,
226 + array $parentSubfieldKeys,
227 + array $submissionData
228 + ): string {
229 + return $this->getCompoundFieldValue($fieldId, $parentChildrenMap, $parentSubfieldKeys, $submissionData);
230 + }
231 +
232 + /**
147 233 * Build a map of field entities indexed by field ID.
148 234 *
149 235 * @param array<int, array<string, mixed>> $entryFields
150 236 * @return array<int, object>
@@ -166,21 +252,22 @@
166 252 *
167 253 * @param string $fieldType
168 254 * @param mixed $value
169 255 * @param bool $skipFormatting
256 + * @param object|null $field
170 257 * @return mixed
171 258 * @SuppressWarnings(PHPMD)
172 259 */
173 - private function formatFieldValue(string $fieldType, $value, bool $skipFormatting = false)
260 + private function formatFieldValue(string $fieldType, $value, bool $skipFormatting = false, ?object $field = null)
174 261 {
175 262 // Convert timestamp to HH:MM format for time fields
176 263 if ($fieldType === 'time' && is_numeric($value)) {
177 - $value = DateTimeHelper::timestampToTime((int)$value);
264 + $value = TimeHelper::timestampToTime((int)$value);
178 265 }
179 266
180 267 // Convert timestamp to date format for date fields
181 268 if ($fieldType === 'date' && is_numeric($value)) {
182 - $value = DateTimeHelper::timestampToDate((int)$value);
269 + $value = DateHelper::timestampToDate((int)$value);
183 270 }
184 271
185 272 /**
186 273 * Filters the formatted field value for frontend display.
@@ -201,11 +288,12 @@
201 288 * @since 0.1.0
202 289 *
203 290 * @param mixed $value The field value to format.
204 291 * @param bool $skipFormatting Whether the field value should be formatted.
292 + * @param object|null $field The field entity object.
205 293 * @return mixed The formatted field value.
206 294 */
207 - return apply_filters("ivyforms/entry/field/format_value/{$fieldType}", $value, $skipFormatting);
295 + return apply_filters("ivyforms/entry/field/format_value/{$fieldType}", $value, $skipFormatting, $field);
208 296 }
209 297
210 298 /**
211 299 * Get the value of a parent subfield.