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
ivyforms / backend / src / Common / Helpers / Import / ThirdPartyAddressFieldMapper.php

ThirdPartyAddressFieldMapper.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Common/Helpers/Import/ThirdPartyAddressFieldMapper.php

67 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Common\Helpers\Import;
4
5 /**
6 * Build an IvyForms composite address field from third-party address parts.
7 */
8 class ThirdPartyAddressFieldMapper
9 {
10 /**
11 * @param string $label
12 * @param string $description
13 * @param bool $required
14 * @param array<int, array<string, mixed>> $parts
15 * @param array<int, array<string, mixed>> $fields
16 * @param array<string, int> $context
17 * @return void
18 */
19 public static function append(
20 string $label,
21 string $description,
22 bool $required,
23 array $parts,
24 array &$fields,
25 array &$context
26 ): void {
27 $parentIndex = $context['fieldIndex']++;
28 $fields[] = [
29 'id' => $context['id']++,
30 'fieldIndex' => $parentIndex,
31 'type' => 'address',
32 'label' => sanitize_text_field($label),
33 'placeholder' => '',
34 'description' => sanitize_text_field($description),
35 'required' => $required,
36 'defaultValue' => '',
37 'parentId' => null,
38 'position' => $context['position']++,
39 'rowIndex' => $context['rowIndex']++,
40 'columnIndex' => 0,
41 'width' => 100,
42 ];
43
44 $position = 1;
45 foreach ($parts as $part) {
46 if (($part['visible'] ?? true) === false) {
47 continue;
48 }
49
50 $addressType = (string) ($part['type'] ?? '');
51 $fields[] = [
52 'id' => $context['id']++,
53 'fieldIndex' => $parentIndex,
54 'type' => 'text',
55 'label' => sanitize_text_field((string) ($part['label'] ?? '')),
56 'placeholder' => sanitize_text_field((string) ($part['placeholder'] ?? '')),
57 'required' => $addressType === 'addressLine2' ? false : $required,
58 'defaultValue' => sanitize_text_field((string) ($part['defaultValue'] ?? '')),
59 'parentId' => $parentIndex,
60 'position' => $position++,
61 'visible' => true,
62 'settings' => wp_json_encode(['addressFieldType' => $addressType]) ?: '',
63 ];
64 }
65 }
66 }
67