From e7810e2066d567c8d421b052297c57cc833a175a Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 20 Dec 2023 09:39:01 +0100 Subject: [PATCH] correctly merge fielddetails with prefetched-formfielddata in form-processing Signed-off-by: Michael Kaufmann --- lib/Froxlor/UI/Form.php | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/lib/Froxlor/UI/Form.php b/lib/Froxlor/UI/Form.php index 694fd3d941..d17c911e3d 100644 --- a/lib/Froxlor/UI/Form.php +++ b/lib/Froxlor/UI/Form.php @@ -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']); } } @@ -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]; } } @@ -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); @@ -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)