From 68929506088ad9dd4d706f7ccd29fe95f554165b Mon Sep 17 00:00:00 2001 From: Jamie Oastler Date: Tue, 30 Aug 2022 16:22:00 -0400 Subject: [PATCH 1/4] gravity-forms/gw-list-field-as-choices - Add filter to expand how the list values can be populated --- .../gw-list-field-as-choices-usage.php | 28 +++++++++++++++++++ gravity-forms/gw-list-field-as-choices.php | 10 +++++++ 2 files changed, 38 insertions(+) diff --git a/gravity-forms/gw-list-field-as-choices-usage.php b/gravity-forms/gw-list-field-as-choices-usage.php index 7ab392509..6029c2ea4 100644 --- a/gravity-forms/gw-list-field-as-choices-usage.php +++ b/gravity-forms/gw-list-field-as-choices-usage.php @@ -34,3 +34,31 @@ 'label_template' => '{Name} ({Age})', 'value_template' => '{Name}', ) ); + + +/** Usage of filters in the snippet */ + +//Customization values based on a user input step from Gravity Flow - The entry list field has already been populated. +/* +add_filter( 'gplibrary_list_field_choices', 'example_flow_list_choice_populate', 10, 3 ); +function example_flow_list_choice_populate( $values, $form, $args) { + if ( is_array( $values ) ) { + return $values; + } + + //Confirm we are within a Gravity Flow Inbox + if( rgget( 'lid' ) && rgget( 'page') == 'gravityflow-inbox' ) { + $entry = GFAPI::get_entry( (int)rgget('lid') ); + //Verify the entry list field has previously stored values to use. + if ( $entry ) { + $values = unserialize( $entry[ $args['list_field_id'] ] ); + if ( ! is_array( $values ) ) { + return false; + } else { + return $values; + } + } + } + return false; +} +*/ \ No newline at end of file diff --git a/gravity-forms/gw-list-field-as-choices.php b/gravity-forms/gw-list-field-as-choices.php index 597048058..725d2b6c5 100644 --- a/gravity-forms/gw-list-field-as-choices.php +++ b/gravity-forms/gw-list-field-as-choices.php @@ -48,6 +48,16 @@ function populate_choice_fields( $form ) { $list_field = GFFormsModel::get_field( $form, $this->_args['list_field_id'] ); $values = GFFormsModel::get_field_value( $list_field ); + /** + * Filter whether to return the form or continue with $values populated via filter. + * + * Allows 3rd parties to avoid customize values for choice use. + * + * @param array|mixed|string $values + * @param array $form + * @param array $args + */ + $values = apply_filters( 'gplibrary_list_field_choices', $values, $form, $this->_args ); // if list field doesn't have any values, let's ditch this party if ( ! is_array( $values ) ) { return $form; From e3069c72d319be440f3eaec4b98fed556a859aa5 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 31 Aug 2022 09:09:32 -0400 Subject: [PATCH 2/4] Update gw-list-field-as-choices-usage.php --- .../gw-list-field-as-choices-usage.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gravity-forms/gw-list-field-as-choices-usage.php b/gravity-forms/gw-list-field-as-choices-usage.php index 6029c2ea4..3cd7a030a 100644 --- a/gravity-forms/gw-list-field-as-choices-usage.php +++ b/gravity-forms/gw-list-field-as-choices-usage.php @@ -35,21 +35,18 @@ 'value_template' => '{Name}', ) ); +# Filter Usage -/** Usage of filters in the snippet */ - -//Customization values based on a user input step from Gravity Flow - The entry list field has already been populated. -/* -add_filter( 'gplibrary_list_field_choices', 'example_flow_list_choice_populate', 10, 3 ); -function example_flow_list_choice_populate( $values, $form, $args) { +## Customize choices to be populated based on Gravity Flow User Input step. +add_filter( 'gwlfac_list_field_choices', function( $values, $form, $args ) { if ( is_array( $values ) ) { return $values; } - //Confirm we are within a Gravity Flow Inbox - if( rgget( 'lid' ) && rgget( 'page') == 'gravityflow-inbox' ) { - $entry = GFAPI::get_entry( (int)rgget('lid') ); - //Verify the entry list field has previously stored values to use. + // Confirm we are within a Gravity Flow Inbox. + if ( rgget( 'lid' ) && rgget( 'page') == 'gravityflow-inbox' ) { + $entry = GFAPI::get_entry( (int) rgget( 'lid' ) ); + // Verify the entry list field has previously stored values to use. if ( $entry ) { $values = unserialize( $entry[ $args['list_field_id'] ] ); if ( ! is_array( $values ) ) { @@ -60,5 +57,4 @@ function example_flow_list_choice_populate( $values, $form, $args) { } } return false; -} -*/ \ No newline at end of file +}, 10, 3 ); From 721198b76a11d342626f47d6c90890b8b1a7f4de Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 31 Aug 2022 09:12:28 -0400 Subject: [PATCH 3/4] Update gw-list-field-as-choices.php --- gravity-forms/gw-list-field-as-choices.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/gravity-forms/gw-list-field-as-choices.php b/gravity-forms/gw-list-field-as-choices.php index 725d2b6c5..a9bd0f8d2 100644 --- a/gravity-forms/gw-list-field-as-choices.php +++ b/gravity-forms/gw-list-field-as-choices.php @@ -49,15 +49,14 @@ function populate_choice_fields( $form ) { $values = GFFormsModel::get_field_value( $list_field ); /** - * Filter whether to return the form or continue with $values populated via filter. + * Filter the values from the List field that will be used to populate field choices. * - * Allows 3rd parties to avoid customize values for choice use. - * - * @param array|mixed|string $values - * @param array $form - * @param array $args + * @param array|mixed|string $values The List field values that will be used to populate field choices. + * @param array $form The current form. + * @param array $args The arguments used to initialize this instance of GW_List_Field_As_Choices. */ - $values = apply_filters( 'gplibrary_list_field_choices', $values, $form, $this->_args ); + $values = apply_filters( 'gwlfac_list_field_values', $values, $form, $this->_args ); + // if list field doesn't have any values, let's ditch this party if ( ! is_array( $values ) ) { return $form; From 9d6aabf43bd672cd88bbe050232427ec2e0dda6c Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 31 Aug 2022 09:12:58 -0400 Subject: [PATCH 4/4] Update gw-list-field-as-choices-usage.php --- gravity-forms/gw-list-field-as-choices-usage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity-forms/gw-list-field-as-choices-usage.php b/gravity-forms/gw-list-field-as-choices-usage.php index 3cd7a030a..41cd24cc8 100644 --- a/gravity-forms/gw-list-field-as-choices-usage.php +++ b/gravity-forms/gw-list-field-as-choices-usage.php @@ -37,8 +37,8 @@ # Filter Usage -## Customize choices to be populated based on Gravity Flow User Input step. -add_filter( 'gwlfac_list_field_choices', function( $values, $form, $args ) { +## Customize List field values to be populated as choices based on Gravity Flow User Input step. +add_filter( 'gwlfac_list_field_values', function( $values, $form, $args ) { if ( is_array( $values ) ) { return $values; }