| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Common\Helpers\Import; |
| 4 |
|
| 5 |
/** |
| 6 |
* Detect WS Form consent checkboxes and map them to IvyForms GDPR fields. |
| 7 |
* |
| 8 |
* WS Form has no GDPR field type; consent is modelled as a checkbox with a |
| 9 |
* single required option. IvyForms has a dedicated GDPR field, so that shape |
| 10 |
* is remapped during import. |
| 11 |
*/ |
| 12 |
class WsFormGdprFieldMapper |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Whether a mapped checkbox should become an IvyForms GDPR field. |
| 16 |
* |
| 17 |
* @param string $wsType |
| 18 |
* @param array<string, mixed> $meta |
| 19 |
* @return bool |
| 20 |
*/ |
| 21 |
public static function matches(string $wsType, array $meta): bool |
| 22 |
{ |
| 23 |
return $wsType === 'checkbox' |
| 24 |
&& WsFormOptionsExtractor::extractConsentText($meta) !== null; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Apply GDPR-specific properties to an already-built field payload. |
| 29 |
* |
| 30 |
* @param array<string, mixed> $field |
| 31 |
* @param array<string, mixed> $meta |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public static function apply(array &$field, array $meta): void |
| 35 |
{ |
| 36 |
$agreementText = WsFormOptionsExtractor::extractConsentText($meta); |
| 37 |
$field['type'] = 'gdpr'; |
| 38 |
$field['required'] = true; |
| 39 |
$field['defaultValue'] = ''; |
| 40 |
$field['agreementText'] = $agreementText !== null ? $agreementText : ''; |
| 41 |
// WS Form hides the field label for consent checkboxes (label_render off); |
| 42 |
// IvyForms shows label and agreement text separately. |
| 43 |
$field['hideLabel'] = false; |
| 44 |
} |
| 45 |
} |
| 46 |
|