Skip to content

Commit 7c466de

Browse files
committed
gpnf-override-parent-merge-tag-on-submission.php: Fixed an issue with parent merge tags not updating Time value on entry edit.
1 parent d643b41 commit 7c466de

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

gp-nested-forms/gpnf-override-parent-merge-tag-on-submission.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,39 @@ function override_child_entry_input_value( $entry, $field, $child_form, $input_i
131131
$child_entry = GFAPI::get_entry( $child_entry_id );
132132
$value = GFCommon::replace_variables( $default_value, $child_form, $child_entry );
133133
GFAPI::update_entry_field( $child_entry_id, $input_id, $value );
134+
135+
// If because of the field update, any formula evaluation should be done on the entry.
136+
$this->reprocess_form_calculations( $child_entry_id );
134137
}
135138

136139
}
140+
141+
function reprocess_form_calculations( $entry_id ) {
142+
$entry = GFAPI::get_entry( $entry_id );
143+
$form = GFAPI::get_form( $entry['form_id'] );
144+
145+
foreach ( $form['fields'] as $field ) {
146+
// Only process calculation fields
147+
if ( $field->enableCalculation && $field->calculationFormula ) {
148+
$field_id = $field->id;
149+
150+
// Retrieve the formula for this field and process. First check for GPDTC calculations because of ':' calculations.
151+
if ( is_callable( array( gp_date_time_calculator(), 'modify_calculation_formula' ) ) ) {
152+
$formula = gp_date_time_calculator()->modify_calculation_formula( $field->calculationFormula, $field, $form, $entry );
153+
}
154+
155+
// Process any other filter customization over it.
156+
$formula = apply_filters( 'gform_calculation_formula', $formula, $form, $field, $entry );
157+
158+
// Process/Calculate the formula
159+
$parsed_formula = GFCommon::replace_variables( $formula, $form, $entry, false, false, false, 'text' );
160+
$calculated_value = eval( 'return ' . $parsed_formula . ';' );
161+
162+
// Update the entry with the recalculated value
163+
GFAPI::update_entry_field( $entry_id, $field_id, $calculated_value );
164+
}
165+
}
166+
}
137167
}
138168

139169
# -------------------------------------------------

0 commit comments

Comments
 (0)