Skip to content

Commit

Permalink
correctly merge fielddetails with prefetched-formfielddata in form-pr…
Browse files Browse the repository at this point in the history
…ocessing

Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Dec 20, 2023
1 parent 4879446 commit e7810e2
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions lib/Froxlor/UI/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public static function prefetchFormFieldData($fieldname, $fielddata)
{
$returnvalue = [];
if (is_array($fielddata) && isset($fielddata['type']) && $fielddata['type'] == 'select') {
if ((!isset($fielddata['select_var']) || !is_array($fielddata['select_var']) || empty($fielddata['select_var'])) && (isset($fielddata['option_options_method']))) {
if ((!is_array($fielddata['select_var']) || empty($fielddata['select_var'])) && (isset($fielddata['option_options_method']))) {
$returnvalue['select_var'] = call_user_func($fielddata['option_options_method']);
}
}
Expand All @@ -236,8 +236,8 @@ public static function processForm(&$form, &$input, $url_params = [], $part = nu
if (\Froxlor\Validate\Form::validateFieldDefinition($groupdetails)) {
// Prefetch form fields
foreach ($groupdetails['fields'] as $fieldname => $fielddetails) {
if (!$only_enabledisable || ($only_enabledisable && isset($fielddetails['overview_option']))) {
$groupdetails['fields'][$fieldname] = self::arrayMergePrefix($fielddetails, $fielddetails['type'], self::prefetchFormFieldData($fieldname, $fielddetails));
if (!$only_enabledisable || isset($fielddetails['overview_option'])) {
$groupdetails['fields'][$fieldname] = array_merge($fielddetails, self::prefetchFormFieldData($fieldname, $fielddetails));
$form['groups'][$groupname]['fields'][$fieldname] = $groupdetails['fields'][$fieldname];
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ public static function processForm(&$form, &$input, $url_params = [], $part = nu
if (\Froxlor\Validate\Form::validateFieldDefinition($groupdetails)) {
// Save fields
foreach ($groupdetails['fields'] as $fieldname => $fielddetails) {
if (!$only_enabledisable || ($only_enabledisable && isset($fielddetails['overview_option']))) {
if (!$only_enabledisable || (isset($fielddetails['overview_option']))) {
if (isset($changed_fields[$fieldname])) {
if (($saved_field = self::saveFormField($fieldname, $fielddetails, self::manipulateFormFieldData($fieldname, $fielddetails, $changed_fields[$fieldname]))) !== false) {
$saved_fields = array_merge($saved_fields, $saved_field);
Expand All @@ -364,24 +364,7 @@ public static function processForm(&$form, &$input, $url_params = [], $part = nu
// Save form
return self::saveForm($form, $saved_fields);
}
}

private static function arrayMergePrefix($array1, $key_prefix, $array2)
{
if (is_array($array1) && is_array($array2)) {
if ($key_prefix != '') {
foreach ($array2 as $key => $value) {
$array1[$key_prefix . '_' . $key] = $value;
unset($array2[$key]);
}
unset($array2);
return $array1;
} else {
return array_merge($array1, $array2);
}
} else {
return $array1;
}
return false;
}

public static function getFormFieldData($fieldname, $fielddata, &$input)
Expand Down

0 comments on commit e7810e2

Please sign in to comment.