From 25ad5c0c56ffb19afb45c0b4906001572d78b283 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Sat, 12 Oct 2024 01:49:58 +0530 Subject: [PATCH 1/4] `gpnf-override-parent-merge-tag-on-submission.php`: Fixed an issue with parent merge tags not updating Time value on entry edit. --- .../gpnf-override-parent-merge-tag-on-submission.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php index 523634673..afe8f8324 100644 --- a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php +++ b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php @@ -95,7 +95,11 @@ function override_parent_merge_tags( $entry, $form ) { } foreach ( $inputs as $input ) { - $this->override_child_entry_input_value( $entry, $field, $child_form, $input['id'], rgar( $input, 'defaultValue' ) ); + $default_value = ( $child_field->type != 'time' ) + ? rgar( $input, 'defaultValue' ) + : preg_replace('/(\d+)\.\d+/', '$1', rgar( $child_field['inputs'][0], 'defaultValue' ) ); + + $this->override_child_entry_input_value( $entry, $field, $child_form, $input['id'], $default_value ); } } } From d643b418f2cf802848c8fa527e3076fe340d7330 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Sat, 12 Oct 2024 10:20:09 +0530 Subject: [PATCH 2/4] `gpnf-override-parent-merge-tag-on-submission.php`: Fixed an issue with parent merge tags not updating Time value on entry edit. --- .../gpnf-override-parent-merge-tag-on-submission.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php index afe8f8324..43d386fbe 100644 --- a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php +++ b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php @@ -95,9 +95,14 @@ function override_parent_merge_tags( $entry, $form ) { } foreach ( $inputs as $input ) { - $default_value = ( $child_field->type != 'time' ) - ? rgar( $input, 'defaultValue' ) - : preg_replace('/(\d+)\.\d+/', '$1', rgar( $child_field['inputs'][0], 'defaultValue' ) ); + switch ( $child_field->type ) { + case 'time': + $default_value = preg_replace( '/(\d+)\.\d+/', '$1', rgar( $child_field['inputs'][0], 'defaultValue' ) ); + break; + default: + $default_value = rgar( $input, 'defaultValue' ); + break; + } $this->override_child_entry_input_value( $entry, $field, $child_form, $input['id'], $default_value ); } From 7c466de987ba983ad32a6e28b484c34e89ce05c4 Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Wed, 16 Oct 2024 08:25:34 -0500 Subject: [PATCH 3/4] `gpnf-override-parent-merge-tag-on-submission.php`: Fixed an issue with parent merge tags not updating Time value on entry edit. --- ...verride-parent-merge-tag-on-submission.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php index 43d386fbe..4b591bfeb 100644 --- a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php +++ b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php @@ -131,9 +131,39 @@ function override_child_entry_input_value( $entry, $field, $child_form, $input_i $child_entry = GFAPI::get_entry( $child_entry_id ); $value = GFCommon::replace_variables( $default_value, $child_form, $child_entry ); GFAPI::update_entry_field( $child_entry_id, $input_id, $value ); + + // If because of the field update, any formula evaluation should be done on the entry. + $this->reprocess_form_calculations( $child_entry_id ); } } + + function reprocess_form_calculations( $entry_id ) { + $entry = GFAPI::get_entry( $entry_id ); + $form = GFAPI::get_form( $entry['form_id'] ); + + foreach ( $form['fields'] as $field ) { + // Only process calculation fields + if ( $field->enableCalculation && $field->calculationFormula ) { + $field_id = $field->id; + + // Retrieve the formula for this field and process. First check for GPDTC calculations because of ':' calculations. + if ( is_callable( array( gp_date_time_calculator(), 'modify_calculation_formula' ) ) ) { + $formula = gp_date_time_calculator()->modify_calculation_formula( $field->calculationFormula, $field, $form, $entry ); + } + + // Process any other filter customization over it. + $formula = apply_filters( 'gform_calculation_formula', $formula, $form, $field, $entry ); + + // Process/Calculate the formula + $parsed_formula = GFCommon::replace_variables( $formula, $form, $entry, false, false, false, 'text' ); + $calculated_value = eval( 'return ' . $parsed_formula . ';' ); + + // Update the entry with the recalculated value + GFAPI::update_entry_field( $entry_id, $field_id, $calculated_value ); + } + } + } } # ------------------------------------------------- From 3a1195751622a4aa77b88d200718ad0542ba339a Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Wed, 16 Oct 2024 08:31:38 -0500 Subject: [PATCH 4/4] `gpnf-override-parent-merge-tag-on-submission.php`: Fixed an issue with parent merge tags not updating Time value on entry edit. --- .../gpnf-override-parent-merge-tag-on-submission.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php index 4b591bfeb..e36e6a5bb 100644 --- a/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php +++ b/gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php @@ -156,7 +156,8 @@ function reprocess_form_calculations( $entry_id ) { $formula = apply_filters( 'gform_calculation_formula', $formula, $form, $field, $entry ); // Process/Calculate the formula - $parsed_formula = GFCommon::replace_variables( $formula, $form, $entry, false, false, false, 'text' ); + $parsed_formula = GFCommon::replace_variables( $formula, $form, $entry, false, false, false, 'text' ); + // phpcs:ignore Squiz.PHP.Eval.Discouraged $calculated_value = eval( 'return ' . $parsed_formula . ';' ); // Update the entry with the recalculated value