| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Common\Helpers\Import; |
| 4 |
|
| 5 |
use IvyForms\Services\Translations\BackendStrings; |
| 6 |
|
| 7 |
/** |
| 8 |
* Read Gravity Forms submit copy for IvyForms button settings. |
| 9 |
*/ |
| 10 |
class GravityFormsSubmitLabelMapper |
| 11 |
{ |
| 12 |
/** |
| 13 |
* Gravity stores submit copy on form.button.text. Empty values still show as |
| 14 |
* "Submit" in the Gravity editor, and some exports only keep the text on the |
| 15 |
* submit field label. |
| 16 |
* |
| 17 |
* @param array<string, mixed> $formRaw |
| 18 |
* @return string |
| 19 |
*/ |
| 20 |
public static function extract(array $formRaw): string |
| 21 |
{ |
| 22 |
$button = is_array($formRaw['button'] ?? null) ? $formRaw['button'] : []; |
| 23 |
$label = sanitize_text_field((string) ($button['text'] ?? '')); |
| 24 |
if ($label !== '') { |
| 25 |
return $label; |
| 26 |
} |
| 27 |
|
| 28 |
foreach (($formRaw['fields'] ?? []) as $rawField) { |
| 29 |
if (!is_array($rawField) || ($rawField['type'] ?? '') !== 'submit') { |
| 30 |
continue; |
| 31 |
} |
| 32 |
|
| 33 |
$label = sanitize_text_field((string) ($rawField['label'] ?? '')); |
| 34 |
if ($label !== '') { |
| 35 |
return $label; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
return BackendStrings::getCommonStrings()['submit']; |
| 40 |
} |
| 41 |
} |
| 42 |
|