| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Form; |
| 4 |
|
| 5 |
use FluentForm\App; |
| 6 |
use FluentForm\App\Modules\Acl\Acl; |
| 7 |
use FluentForm\Framework\Foundation\Application; |
| 8 |
use FluentForm\App\Services\FormBuilder\EditorShortcode; |
| 9 |
use FluentForm\Framework\Helpers\ArrayHelper; |
| 10 |
|
| 11 |
class Inputs |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @var \FluentForm\Framework\Request\Request |
| 15 |
*/ |
| 16 |
private $request; |
| 17 |
|
| 18 |
/** |
| 19 |
* Build the class instance |
| 20 |
* @throws \Exception |
| 21 |
*/ |
| 22 |
public function __construct(Application $application) |
| 23 |
{ |
| 24 |
$this->request = $application->request; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Get all the flatten form inputs for shortcode generation. |
| 29 |
*/ |
| 30 |
public function index() |
| 31 |
{ |
| 32 |
$formId = $this->request->get('formId'); |
| 33 |
|
| 34 |
$form = wpFluent()->table('fluentform_forms')->find($formId); |
| 35 |
|
| 36 |
$fields = FormFieldsParser::getShortCodeInputs($form, [ |
| 37 |
'admin_label', 'attributes', 'options' |
| 38 |
]); |
| 39 |
|
| 40 |
$fields = array_filter($fields, function ($field) { |
| 41 |
return in_array($field['element'], $this->supportedConditionalFields()); |
| 42 |
}); |
| 43 |
|
| 44 |
wp_send_json($this->filterEditorFields($fields), 200); |
| 45 |
} |
| 46 |
|
| 47 |
public function supportedConditionalFields() |
| 48 |
{ |
| 49 |
$supportedConditionalFields = [ |
| 50 |
'select', |
| 51 |
'ratings', |
| 52 |
'net_promoter', |
| 53 |
'textarea', |
| 54 |
'shortcode', |
| 55 |
'input_url', |
| 56 |
'input_text', |
| 57 |
'input_date', |
| 58 |
'input_email', |
| 59 |
'input_radio', |
| 60 |
'input_number', |
| 61 |
'select_country', |
| 62 |
'input_checkbox', |
| 63 |
'input_password', |
| 64 |
'terms_and_condition', |
| 65 |
'gdpr_agreement', |
| 66 |
'input_hidden', |
| 67 |
'input_file', |
| 68 |
'input_image', |
| 69 |
'subscription_payment_component' |
| 70 |
]; |
| 71 |
|
| 72 |
return apply_filters('fluentform_supported_conditional_fields', $supportedConditionalFields); |
| 73 |
} |
| 74 |
|
| 75 |
public function filterEditorFields($fields) |
| 76 |
{ |
| 77 |
foreach ($fields as $index => $field) { |
| 78 |
$element = ArrayHelper::get($field, 'element'); |
| 79 |
if($element == 'select_country') { |
| 80 |
$fields[$index]['options'] = App::load( |
| 81 |
App::appPath('Services/FormBuilder/CountryNames.php') |
| 82 |
); |
| 83 |
} else if($element == 'gdpr-agreement' || $element == 'terms_and_condition') { |
| 84 |
$fields[$index]['options'] = array('on' => 'Checked'); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
return $fields; |
| 89 |
} |
| 90 |
} |
| 91 |
|