Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions gravity-forms/gw-list-field-as-choices-usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,27 @@
'label_template' => '{Name} <span style="color:#999;font-style:italic;">({Age})</span>',
'value_template' => '{Name}',
) );

# Filter Usage

## 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;
}

// 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;
}, 10, 3 );
9 changes: 9 additions & 0 deletions gravity-forms/gw-list-field-as-choices.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ function populate_choice_fields( $form ) {
$list_field = GFFormsModel::get_field( $form, $this->_args['list_field_id'] );
$values = GFFormsModel::get_field_value( $list_field );

/**
* Filter the values from the List field that will be used to populate field choices.
*
* @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( '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;
Expand Down