gravityflow_entry_[type]_response_mapping

Description

The gravityflow_entry_[type]_response_mapping filter allows the entry to be modified during the response mapping of any step type that uses the response mapping trait. This filter fires once for each response mapping (JSON key to form field) you have defined in the step settings.

Usage

The actual filter name to hook on depends on which step type you are wanting to filter.

1
2
add_filter( 'gravityflow_entry_webhook_response_mapping', 'jo_webhook_map_attachment_details', 10, 5);
add_filter( 'gravityflow_entry_salesforce_response_mapping', 'jo_webhook_map_attachment_details', 10, 5);

Parameters

ParameterTypeDetails
$entryEntryThe entry currently being processed.
$mappingArrayThe mapping currently being processed.
$dataArrayThe response headers or body data.
$stepStepThe current step.
$mapping_typeStringThe mapping type: header or body.

Examples

All of the examples shown below reference the outgoing webhook step type that is a core part of Gravity Flow. You can tell if another step type would support

Convert an array of JSON values into a paragraph field as html

Your step type outgoing webhook step calls an API which provides an array of JSON values that you would like to map into a paragraph field with html.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
add_filter( 'gravityflow_entry_webhook_response_mapping', 'sh_filter_gravityflow_entry_webhook_mapping', 10, 4 );
function sh_filter_gravityflow_entry_webhook_mapping( $entry, $mapping, $data, $step ) {
        //Parse a complex response object for a defined field mapping - example uses https://www.markerapi.com/
    if( $mapping[ 'custom_key' ] == 'trademarks' ) {
            if( is_array( $data[ 'trademarks' ] ) ){
                    $field = '<ul>';
                    foreach( $data[ 'trademarks' ] as $trademark )  {
                        $field .= '<li><strong>' . $trademark['wordmark'] . ' - ' . $trademark['code'] . '</strong><br/>' . $trademark['description'] . '</li>';
                    }
                    $field .= '</ul>';
 
                    $entry[ $mapping[ 'value' ] ] = $field;
            }
        }
    return $entry;
}

Since

  • Version 2.2.4 – Filter added
  • Version 2.9.7 – Added the $mapping_type parameter
  • Version 2.9.10 – Refactored to have filter defined as part of Response_Mapping trait.
    Filter name will include step type. Prior to this version it was fixed as gravityflow_entry_webhook_response_mapping specific to the Outgoing Webhook step.

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?