32 var
$icon =
'dashicons-location-alt';
38 $this->label = esc_html__(
'Address',
'gk-gravityview' );
42 parent::__construct();
53 add_filter(
'gravityview/extension/search/input_type', array( $this,
'search_bar_input_type' ), 10, 3 );
54 add_filter(
'gravityview/search/input_types', array( $this,
'input_types' ) );
55 add_filter(
'gravityview_widget_search_filters', array( $this,
'search_field_filter' ), 10, 3 );
73 if (
'address' !== \
GV\Utils::get( $search_field,
'type' ) ) {
77 $field_id = intval( floor( $search_field[
'key'] ) );
86 $method_name =
'get_choices_' . self::get_input_type_from_input_id(
$input_id );
87 if( method_exists( $this, $method_name ) ) {
92 $choices = $this->{$method_name}( $address_field,
$form );
95 if( ! empty( $choices ) ) {
96 $search_field[
'choices'] = $choices;
99 $search_field[
'type'] =
'text';
100 $search_field[
'input'] =
'input_text';
104 return $search_fields;
120 $countries = $address_field->get_countries();
122 $country_choices = array();
124 foreach ( $countries as $key => $country ) {
125 $country_choices[] = array(
131 return $country_choices;
150 $address_type = empty( $address_field->addressType ) ? $address_field->get_default_address_type(
$form[
'id'] ) : $address_field->addressType;
152 $state_choices = array();
154 switch ( $address_type ) {
156 $states = GFCommon::get_us_states();
159 $states = GFCommon::get_canadian_provinces();
162 $address_types = $address_field->get_address_types(
$form[
'id'] );
163 $states = empty( $address_types[ $address_type ][
'states'] ) ? array() : $address_types[ $address_type ][
'states'];
167 foreach ( $states as $key => $state ) {
168 if ( is_array( $state ) ) {
169 $state_subchoices = array();
171 foreach ( $state as $key => $substate ) {
172 $state_subchoices[] = array(
173 'value' => is_numeric( $key ) ? $substate : $key,
178 $state_choices[] = array(
180 'value' => $state_subchoices,
184 $state_choices[] = array(
185 'value' => is_numeric( $key ) ? $state : $key,
191 return $state_choices;
208 $input_types[
'street'] = $text_inputs;
209 $input_types[
'street2'] = $text_inputs;
210 $input_types[
'city'] = $text_inputs;
212 $input_types[
'state'] = array(
'select',
'radio',
'link' ) + $text_inputs;
213 $input_types[
'zip'] = array(
'input_text' );
214 $input_types[
'country'] = array(
'select',
'radio',
'link' ) + $text_inputs;
235 if(
'address' !== $field_type &&
$input_id ) {
240 if( $address_field_name = self::get_input_type_from_input_id(
$input_id ) ) {
241 $input_type = $address_field_name;
262 $input_type =
'street';
265 $input_type =
'street2';
268 $input_type =
'city';
271 $input_type =
'state';
277 $input_type =
'country';
288 return $field_options;
291 if(
'edit' === $context ) {
292 return $field_options;
295 $add_options = array();
297 $add_options[
'show_map_link'] = array(
298 'type' =>
'checkbox',
299 'label' => __(
'Show Map Link:',
'gk-gravityview' ),
300 'desc' => __(
'Display a "Map It" link below the address',
'gk-gravityview' ),
302 'merge_tags' =>
false,
303 'group' =>
'display',
307 $add_options[
'show_map_link_new_window'] = array(
308 'type' =>
'checkbox',
309 'label' => __(
'Open map link in a new tab or window?',
'gk-gravityview' ),
311 'merge_tags' =>
false,
312 'group' =>
'display',
313 'requires' =>
'show_map_link',
317 return $add_options + $field_options;
Modify field settings by extending this class.
static getInstance( $passed_post=NULL)
static get_input_type_from_input_id( $input_id)
Get a name for the input based on the input ID.
get_choices_country( $address_field)
Get array of countries to use for the search choices.
new GravityView_Field_Address
get_choices_state( $address_field, $form)
Get array of states to use for the search choices.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
search_bar_input_type( $input_type, $field_type, $field_id)
Converts the custom input type (address) into the selected type.
if(gravityview() ->plugin->is_GF_25()) $form
gravityview_get_input_id_from_id( $field_id='')
Very commonly needed: get the # of the input based on a full field ID.
add_hooks()
Add filters for this field type.
input_types( $input_types)
Add the input types available for each custom search field type.
search_field_filter( $search_fields, $widget, $widget_args)
Dynamically add choices to the address field dropdowns, if any.
if(empty( $created_by)) $form_id
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
Add custom options for address fields.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed