gravityflowformconnector_update_entry_id

Description

The gravityflowformconnector_update_entry_id filter allows the target entry ID to be modified during the Form Connector Update an Entry step type. For the equivalent with the Update Fields step type use the gravityflowformconnector_target_entry_id filter that has same function/parameter definition.

Parameters

ParameterTypeDefinition
$target_entry_idIntegerThe target entry id.
$target_form_idIntegerThe target form id.
$entryEntryThe current entry object.
$formFormThe current form object.
$stepStepThe current step object.

Examples

Custom search for the target entry ID based on the value of field ID 4.

1
2
3
4
5
6
7
8
9
add_filter( 'gravityflowformconnector_update_entry_id', 'sh_gravityflowformconnector_update_entry_id', 10, 5);
  function sh_gravityflowformconnector_update_entry_id( $target_entry_id, $target_form_id, $entry, $form, $step ) {
      // Custom search for the target entry ID based on the value of field ID 4.
      $search_criteria['status'] = 'active';
      $search_criteria['field_filters'][] = array( 'key' => '2', 'value' => $entry['4'] );
      $entries = GFAPI::get_entries( $target_form_id, $search_criteria );
      // Return the ID of the first entry in the results.
      return $entries[0]['id'];
  }

Custom search for the target entry ID across multiple form fields’ for multiple steps.

Similar to Example 1 in it’s use of the GFAPI::get_entries function, it compares the entry field value against multiple form fields based on the particular step. 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
add_filter( 'gravityflowformconnector_update_entry_id', 'match_first_matters_id', 10, 5 );
function match_first_matters_id( $target_entry_id, $target_form_id, $entry, $form, $step ) {
  
    if ( false == $step ) {
        return false;
    }
 
    //Ensure this filter only applies for the desired form ID.
    if ( $form['id'] != '15' ) {
        return $target_entry_id;
    }
 
    $step_id = $step->get_id();
 
    //Update the list of step IDs you want this to execute against
    if ( false == in_array( $step_id, array( '65', '66', '68', '69', '70', '71' ) ) ) {
        return $target_entry_id;
    }
 
    $original_matter_name = $entry['1'];
 
    switch ($step_id):
        //Adjust step ID (case), search_form_id and the field in it to match your use case
        case 65:
        case 66:
            $search_form_id = '17';
            $search_criteria['field_filters'][] = array( 'key' => '3', 'value' => $original_matter_name );
        break;
 
        //Adjust step ID (case), search_form_id and the field in it to match your use case
        case 68:
        case 69:
            $search_form_id = '18';
            $search_criteria['field_filters'][] = array( 'key' => '2', 'value' => $original_matter_name );
            break;
    endswitch;
     
    $paging         = array( 'offset' => 0, 'page_size' => 1 );
    $total_count    = 0;
    $matched_entries = GFAPI::get_entries( $search_form_id, $search_criteria, array(), $paging, $total_count );
 
    if( ! empty( $matched_entries ) ) {
        foreach( $matched_entries as $matched_entry ) {
            return $matched_entry['id'];
        }
    }
 
    return $target_entry_id;
}

When combined with example 5 from the gravityflow_step_is_condition_met filter docs, you can use two Form Connector Update an Entry steps to ensure all entries which match the expected field value get changed.  If using this approach, you would setup two Update an Entry steps with the same settings as shown in this screenshot. The first would have it’s Next Step setting point to ‘Next step in List’ while the second would point back to the first. In that way, as soon as the series of steps both fail their gravityflow_step_is_condition_met filter, you know that all entries have been updated.

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?