Skip to content
Snippets Groups Projects
Commit dd00d417 authored by Lucas García's avatar Lucas García
Browse files

feat: field interface standarization

parent be8da82d
No related branches found
No related tags found
No related merge requests found
......@@ -56,12 +56,33 @@ class Integration extends BaseIntegration
? $field->adminLabel
: $field->label);
$inputs = $field->get_entry_inputs();
if (is_array($inputs)) {
$inputs = array_map(function ($input) {
return ['name' => $input['name'], 'label' => $input['label'], 'id' => $input['id']];
}, array_filter($inputs, function ($input) {
return $input['name'];
}));
} else {
$inputs = [];
}
$options = [];
if (is_array($field->choices)) {
$options = array_map(function ($opt) {
return ['value' => $opt['value'], 'label' => $opt['text']];
}, $field->choices);
}
return [
'id' => $field->id,
'type' => $type,
'name' => $name,
'label' => $field->label,
'id' => $field->id,
'inputs' => $field->get_entry_inputs(),
'required' => $field->isRequired,
'options' => $options,
'inputs' => $inputs,
'conditional' => is_array($field->conditionalLogic) && $field->conditionalLogic['enabled'],
];
}
......@@ -85,7 +106,7 @@ class Integration extends BaseIntegration
$input_name = $field['name'];
$inputs = $field['inputs'];
if (is_array($inputs)) {
if (!empty($inputs)) {
// composed fields
$names = array_map(function ($input) {
return $input['name'];
......
......@@ -50,12 +50,30 @@ class Integration extends BaseIntegration
public function serialize_field($field, $form)
{
$type = $field->basetype;
if ($type === 'conditional') {
$type = $field->get_option('type')[0];
}
$options = [];
if (is_array($field->values)) {
$values = $field->pipes->collect_afters();
for ($i = 0; $i < sizeof($field->raw_values); $i++) {
$options[] = [
'value' => $values[$i],
'label' => $field->labels[$i],
];
}
}
return [
'type' => $field->basetype,
'name' => $field->rawname,
'label' => $field->labels,
'values' => $field->values,
'id' => null,
'id' => $field->get_id_option(),
'type' => $type,
'name' => $field->raw_name,
'label' => $field->name,
'required' => $field->is_required(),
'options' => $options,
'conditional' => $field->basetype === 'conditional' || $field->basetype === 'fileconditional',
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment