| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Common\Helpers\Import; |
| 4 |
|
| 5 |
/** |
| 6 |
* Map a Gravity Forms address field and its visible inputs. |
| 7 |
*/ |
| 8 |
class GravityFormsAddressFieldMapper |
| 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 |
$typeMap = [ |
| 19 |
'1' => 'streetAddress', |
| 20 |
'2' => 'addressLine2', |
| 21 |
'3' => 'city', |
| 22 |
'4' => 'state', |
| 23 |
'5' => 'zip', |
| 24 |
'6' => 'country', |
| 25 |
]; |
| 26 |
$parts = []; |
| 27 |
|
| 28 |
foreach (($rawField['inputs'] ?? []) as $input) { |
| 29 |
if (!is_array($input)) { |
| 30 |
continue; |
| 31 |
} |
| 32 |
|
| 33 |
$inputIdParts = explode('.', (string) ($input['id'] ?? '')); |
| 34 |
$suffix = (string) end($inputIdParts); |
| 35 |
if (!isset($typeMap[$suffix])) { |
| 36 |
continue; |
| 37 |
} |
| 38 |
|
| 39 |
$parts[] = [ |
| 40 |
'type' => $typeMap[$suffix], |
| 41 |
'label' => $input['label'] ?? '', |
| 42 |
'placeholder' => $input['placeholder'] ?? '', |
| 43 |
'defaultValue' => $input['defaultValue'] ?? '', |
| 44 |
'visible' => empty($input['isHidden']), |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
ThirdPartyAddressFieldMapper::append( |
| 49 |
(string) ($rawField['label'] ?? ''), |
| 50 |
(string) ($rawField['description'] ?? ''), |
| 51 |
!empty($rawField['isRequired']), |
| 52 |
$parts, |
| 53 |
$fields, |
| 54 |
$context |
| 55 |
); |
| 56 |
} |
| 57 |
} |
| 58 |
|