Skip to content

Commit 3559587

Browse files
authored
gpnf-override-parent-merge-tag-on-submission.php: Fixed issue with child entry's merge tag not getting replaced when used in combination with the {Parent} merge tag.
1 parent 4874454 commit 3559587

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ function override_parent_merge_tags( $entry, $form ) {
9595
}
9696

9797
foreach ( $inputs as $input ) {
98-
$this->override_child_entry_input_value( $entry, $field, $input['id'], rgar( $input, 'defaultValue' ) );
98+
$this->override_child_entry_input_value( $entry, $field, $child_form, $input['id'], rgar( $input, 'defaultValue' ) );
9999
}
100100
}
101101
}
102102

103103
return $entry;
104104
}
105105

106-
function override_child_entry_input_value( $entry, $field, $input_id, $default_value ) {
106+
function override_child_entry_input_value( $entry, $field, $child_form, $input_id, $default_value ) {
107107

108108
preg_match_all( '/{Parent:(\d+(\.\d+)?)[^}]*}/i', $default_value, $matches, PREG_SET_ORDER );
109109
if ( empty( $matches ) ) {
@@ -115,8 +115,12 @@ function override_child_entry_input_value( $entry, $field, $input_id, $default_v
115115
$value = str_replace( $match[0], rgar( $entry, $match[1] ), $value );
116116
}
117117

118+
$default_value = $value;
118119
$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
119120
foreach ( $child_entry_ids as $child_entry_id ) {
121+
// If any child entry merge tag is present, replace it with the child entry value before replacing with the Parent merge tag values.
122+
$child_entry = GFAPI::get_entry( $child_entry_id );
123+
$value = GFCommon::replace_variables( $default_value, $child_form, $child_entry );
120124
GFAPI::update_entry_field( $child_entry_id, $input_id, $value );
121125
}
122126

0 commit comments

Comments
 (0)