Skip to content

Commit e19a0e3

Browse files
authored
gpeb-use-select-for-country-filter.php: Migrated from experimental folder.
1 parent e21b59b commit e19a0e3

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Gravity Perks // Entry Blocks // Filters Block: Use Select for Country Input Filter
4+
* https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
5+
*
6+
* Experimental Snippet 🧪
7+
*
8+
* All input fields in the Entry Blocks filter are text inputs by default. This snippet changes the input type to a
9+
* select for the Address field's Country input.
10+
*/
11+
add_filter( 'gpeb_filter_form_field', function ( $field ) {
12+
if ( ! rgar( $field, 'gpebFilterInputField' ) ) {
13+
return $field;
14+
}
15+
16+
$input_field = $field['gpebFilterInputField'];
17+
18+
// If we're not working with an Address field, return the field as-is.
19+
if ( $input_field['type'] !== 'address' ) {
20+
return $field;
21+
}
22+
23+
// Get the input ID.
24+
$input_id = explode( '.', rgar( $field, 'gpebFilterSearch' ) )[1];
25+
26+
switch ( $input_id ) {
27+
// Country
28+
case 6:
29+
$country_choices = array_map( function ( $country ) {
30+
return array(
31+
'text' => $country,
32+
'value' => $country,
33+
);
34+
}, $field['gpebFilterInputField']->get_countries() );
35+
36+
// Change the field to a select and populate it with countries from the address field.
37+
$new_field = new \GF_Field_Select( array(
38+
'id' => $field['id'],
39+
'label' => $field['label'],
40+
'gpebFilterSearch' => $field['gpebFilterSearch'],
41+
'gpebFilterInputField' => $field['gpebFilterInputField'],
42+
'size' => $field['size'],
43+
'inputs' => $field['inputs'],
44+
'formId' => $field['formId'],
45+
'type' => 'select',
46+
'choices' => $country_choices,
47+
) );
48+
return $new_field;
49+
}
50+
51+
return $field;
52+
} );

0 commit comments

Comments
 (0)