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/Shortcode/ShortcodeService.php +32 -7 1.0 → 1.5.1 View file →
@@ -7,10 +7,12 @@
7 7
8 8 namespace IvyForms\Services\Shortcode;
9 9
10 10 use IvyForms\Common\Exceptions\ValidationException;
11 +use IvyForms\Common\Helpers\FieldHelper;
11 12 use IvyForms\Services\API\IvyFormsAPI;
12 13 use IvyForms\Services\Form\Style\FormStyleService;
14 +use IvyForms\Services\Placeholder\PlaceholderLocalizationHelper;
13 15 use IvyForms\Services\Shortcode\Helpers\ShortcodeHelper;
14 16
15 17 /**
16 18 * Class ShortcodeService
@@ -151,17 +153,16 @@
151 153 * @return array<int, array<string, mixed>>
152 154 */
153 155 private static function prepareFieldsMap(array $fields): array
154 156 {
157 + $generalData = PlaceholderLocalizationHelper::getGeneralData();
155 158 $fieldsMap = [];
156 159 foreach ($fields as $field) {
157 160 $fieldArr = $field->toArray();
161 + $fieldType = isset($fieldArr['type']) ? (string) $fieldArr['type'] : '';
158 162 if (
159 - isset($fieldArr['type']) && in_array(
160 - $fieldArr['type'],
161 - ['radio', 'checkbox', 'select', 'multi-select', 'rating'],
162 - true
163 - )
163 + $fieldType !== ''
164 + && (FieldHelper::fieldTypeHasOptions($fieldType) || $fieldType === 'rating')
164 165 ) {
165 166 $fieldOptions = IvyFormsAPI::getFieldOptions($fieldArr['id']);
166 167 $fieldArr['fieldOptions'] = [];
167 168 foreach ($fieldOptions as $option) {
@@ -169,14 +170,34 @@
169 170 $fieldArr['fieldOptions'][] = $option->toArray();
170 171 }
171 172 }
172 173 }
173 - $fieldsMap[] = $fieldArr;
174 + $fieldsMap[] = self::resolveFieldPlaceholders($fieldArr, $generalData);
174 175 }
175 176 return $fieldsMap;
176 177 }
177 178
178 179 /**
180 + * @param array<string, mixed> $fieldArr
181 + * @param array<string, string|int> $generalData
182 + * @return array<string, mixed>
183 + */
184 + private static function resolveFieldPlaceholders(array $fieldArr, array $generalData): array
185 + {
186 + foreach (['placeholder', 'defaultValue'] as $key) {
187 + if (!isset($fieldArr[$key]) || !is_string($fieldArr[$key])) {
188 + continue;
189 + }
190 + $fieldArr[$key] = PlaceholderLocalizationHelper::resolveFieldString(
191 + $fieldArr[$key],
192 + $generalData
193 + );
194 + }
195 +
196 + return $fieldArr;
197 + }
198 +
199 + /**
179 200 * Enqueue handler
180 201 */
181 202 public static function enqueueScripts(): void
182 203 {
@@ -200,9 +221,13 @@
200 221
201 222 $styleSettings = $formPayload['styleSettings'] ?? null;
202 223
203 224 if (!empty($styleSettings) && is_array($styleSettings)) {
204 - return FormStyleService::generateFormCSS($formId, $styleSettings);
225 + return FormStyleService::generateFormCSS(
226 + $formId,
227 + $styleSettings,
228 + isset($formPayload['formType']) ? (string)$formPayload['formType'] : null
229 + );
205 230 }
206 231 }
207 232 }
208 233