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

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

57 lines 1.8 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 * Map a WPForms address field and its configured sub-fields.
7 */
8 class WpFormsAddressFieldMapper
9 {
10 /**
11 * @param array<string, mixed> $rawField
12 * @param array<int, array<string, mixed>> $fields
13 * @param array<string, int> $context
14 * @return void
15 */
16 public static function append(array $rawField, array &$fields, array &$context): void
17 {
18 $parts = [
19 self::part($rawField, 'address1', 'streetAddress', 'Address Line 1'),
20 self::part($rawField, 'address2', 'addressLine2', 'Address Line 2'),
21 self::part($rawField, 'city', 'city', 'City'),
22 self::part($rawField, 'state', 'state', 'State / Province'),
23 self::part($rawField, 'postal', 'zip', 'Zip / Postal Code'),
24 self::part($rawField, 'country', 'country', 'Country'),
25 ];
26 $parts[5]['visible'] = ($rawField['scheme'] ?? 'us') === 'international'
27 && empty($rawField['country_hide']);
28
29 ThirdPartyAddressFieldMapper::append(
30 (string) ($rawField['label'] ?? ''),
31 (string) ($rawField['description'] ?? ''),
32 !empty($rawField['required']),
33 $parts,
34 $fields,
35 $context
36 );
37 }
38
39 /**
40 * @param array<string, mixed> $rawField
41 * @param string $key
42 * @param string $type
43 * @param string $label
44 * @return array<string, mixed>
45 */
46 private static function part(array $rawField, string $key, string $type, string $label): array
47 {
48 return [
49 'type' => $type,
50 'label' => $label,
51 'placeholder' => $rawField[$key . '_placeholder'] ?? '',
52 'defaultValue' => $rawField[$key . '_default'] ?? '',
53 'visible' => empty($rawField[$key . '_hide']),
54 ];
55 }
56 }
57