Hi Jamie,
I figured out a way that would be nice to do this without the need of adding another extension. Probably you can help me figure what’s wrong in my snippet of code?
Currently the nested form gets its fields updated everytime there’s a Submission of a Workflow step with the snippet below (provided by Gravity perks). I wanted to add the Restart Workflow so that if a check box is selected in the modified nested entry, the workflow will go through the process again and delete the Google Calendar event + delete the entry right after.
Here’s the snippet:
add_filter( 'gform_entry_post_save', 'gpnf_override_parent_merge_tags', 11, 2 );
add_action( 'gform_after_update_entry_26', function ( $form, $entry_id ) {
$entry = GFAPI::get_entry( $entry_id );
gpnf_override_parent_merge_tags( $entry, $form );
}, 11, 2 );
add_filter( 'gravityview-inline-edit/entry-updated', function( $return, $entry, $form_id ) {
gpnf_override_parent_merge_tags( $entry, GFAPI::get_form( $form_id ) );
return $return;
}, 10, 3 );
function gpnf_override_parent_merge_tags( $entry, $form ) {
foreach ( $form['fields'] as $field ) {
if ( $field->get_input_type() === 'form' ) {
$child_form_id = $field->gpnfForm;
$child_form = GFAPI::get_form( $child_form_id );
foreach ( $child_form['fields'] as $child_field ) {
if ( $child_field->get_entry_inputs() ) {
foreach ( $child_field->get_entry_inputs() as $input ) {
preg_match( '/{Parent:(.+)}/i', rgar( $input, 'defaultValue' ), $match );
if ( $match ) {
$value = rgar( $entry, $match[1] );
$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
$api = new Gravity_Flow_API( $child_form_id );
foreach ( $child_entry_ids as $child_entry_id ) {
GFAPI::update_entry_field( $child_entry_id, $input['id'], $value );
$api->restart_workflow( $child_entry_id );
}
}
}
} else {
preg_match( '/{Parent:(.+)}/i', $child_field->defaultValue, $match );
if ( $match ) {
$value = rgar( $entry, $match[1] );
$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
$api = new Gravity_Flow_API( $child_form_id );
foreach ( $child_entry_ids as $child_entry_id ) {
GFAPI::update_entry_field( $child_entry_id, $child_field->id, $value );
$api->restart_workflow( $child_entry_id );
}
}
}
}
}
}
return $entry;
}
In this snippet the following lines are what we are looking to make work:
$api = new Gravity_Flow_API( $child_form_id );
$api->restart_workflow( $child_entry_id );
Do you see what’s wrong with this as it won’t fire the workflow over but will update all nested entries with the data.
Thanks in advance for your help!
Michael