Skip to content

Commit fe104c1

Browse files
Idealienspivurno
authored andcommitted
gravity-forms/gw-list-field-as-choices - Add filter to expand how the list values can be populated
1 parent 04ba3ab commit fe104c1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

gravity-forms/gw-list-field-as-choices-usage.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,31 @@
3434
'label_template' => '{Name} <span style="color:#999;font-style:italic;">({Age})</span>',
3535
'value_template' => '{Name}',
3636
) );
37+
38+
39+
/** Usage of filters in the snippet */
40+
41+
//Customization values based on a user input step from Gravity Flow - The entry list field has already been populated.
42+
/*
43+
add_filter( 'gplibrary_list_field_choices', 'example_flow_list_choice_populate', 10, 3 );
44+
function example_flow_list_choice_populate( $values, $form, $args) {
45+
if ( is_array( $values ) ) {
46+
return $values;
47+
}
48+
49+
//Confirm we are within a Gravity Flow Inbox
50+
if( rgget( 'lid' ) && rgget( 'page') == 'gravityflow-inbox' ) {
51+
$entry = GFAPI::get_entry( (int)rgget('lid') );
52+
//Verify the entry list field has previously stored values to use.
53+
if ( $entry ) {
54+
$values = unserialize( $entry[ $args['list_field_id'] ] );
55+
if ( ! is_array( $values ) ) {
56+
return false;
57+
} else {
58+
return $values;
59+
}
60+
}
61+
}
62+
return false;
63+
}
64+
*/

gravity-forms/gw-list-field-as-choices.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ function populate_choice_fields( $form ) {
4848
$list_field = GFFormsModel::get_field( $form, $this->_args['list_field_id'] );
4949
$values = GFFormsModel::get_field_value( $list_field );
5050

51+
/**
52+
* Filter whether to return the form or continue with $values populated via filter.
53+
*
54+
* Allows 3rd parties to avoid customize values for choice use.
55+
*
56+
* @param array|mixed|string $values
57+
* @param array $form
58+
* @param array $args
59+
*/
60+
$values = apply_filters( 'gplibrary_list_field_choices', $values, $form, $this->_args );
5161
// if list field doesn't have any values, let's ditch this party
5262
if ( ! is_array( $values ) ) {
5363
return $form;

0 commit comments

Comments
 (0)