# ivyforms/1.5.1/backend/src/Common/Helpers/Import/ThirdPartyAddressFieldMapper.php

The Innovative Form Builder – IvyForms, version 1.5.1. 67 lines.

- Page: https://pluginprobe.com/plugins/ivyforms/1.5.1/code/backend/src/Common/Helpers/Import/ThirdPartyAddressFieldMapper.php
- Raw: https://pluginprobe.com/plugins/ivyforms/1.5.1/raw/backend/src/Common/Helpers/Import/ThirdPartyAddressFieldMapper.php
- Modified: 2026-10-05T14:37:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ivyforms/1.5.1/code/backend/src/Common/Helpers/Import/ThirdPartyAddressFieldMapper.php#L10-L20`.

```php
<?php

namespace IvyForms\Common\Helpers\Import;

/**
 * Build an IvyForms composite address field from third-party address parts.
 */
class ThirdPartyAddressFieldMapper
{
    /**
     * @param string $label
     * @param string $description
     * @param bool $required
     * @param array<int, array<string, mixed>> $parts
     * @param array<int, array<string, mixed>> $fields
     * @param array<string, int> $context
     * @return void
     */
    public static function append(
        string $label,
        string $description,
        bool $required,
        array $parts,
        array &$fields,
        array &$context
    ): void {
        $parentIndex = $context['fieldIndex']++;
        $fields[] = [
            'id'           => $context['id']++,
            'fieldIndex'   => $parentIndex,
            'type'         => 'address',
            'label'        => sanitize_text_field($label),
            'placeholder'  => '',
            'description'  => sanitize_text_field($description),
            'required'     => $required,
            'defaultValue' => '',
            'parentId'     => null,
            'position'     => $context['position']++,
            'rowIndex'     => $context['rowIndex']++,
            'columnIndex'  => 0,
            'width'        => 100,
        ];

        $position = 1;
        foreach ($parts as $part) {
            if (($part['visible'] ?? true) === false) {
                continue;
            }

            $addressType = (string) ($part['type'] ?? '');
            $fields[] = [
                'id'           => $context['id']++,
                'fieldIndex'   => $parentIndex,
                'type'         => 'text',
                'label'        => sanitize_text_field((string) ($part['label'] ?? '')),
                'placeholder'  => sanitize_text_field((string) ($part['placeholder'] ?? '')),
                'required'     => $addressType === 'addressLine2' ? false : $required,
                'defaultValue' => sanitize_text_field((string) ($part['defaultValue'] ?? '')),
                'parentId'     => $parentIndex,
                'position'     => $position++,
                'visible'      => true,
                'settings'     => wp_json_encode(['addressFieldType' => $addressType]) ?: '',
            ];
        }
    }
}

```
