1 | <?php |
||
11 | class GravityView_Field_Address extends GravityView_Field { |
||
12 | |||
13 | var $name = 'address'; |
||
14 | |||
15 | var $group = 'advanced'; |
||
16 | |||
17 | var $_gf_field_class_name = 'GF_Field_Address'; |
||
18 | |||
19 | public function __construct() { |
||
26 | |||
27 | /** |
||
28 | * Add filters for this field type |
||
29 | * |
||
30 | * @since 1.19.2 |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | private function add_hooks() { |
||
39 | |||
40 | /** |
||
41 | * Dynamically add choices to the address field dropdowns, if any |
||
42 | * |
||
43 | * @since 1.19.2 |
||
44 | * |
||
45 | * @param array $search_fields Array of search filters with `key`, `label`, `value`, `type` keys |
||
46 | * @param GravityView_Widget_Search $widget Current widget object |
||
47 | * @param array $widget_args Args passed to this method. {@since 1.8} |
||
48 | * |
||
49 | * @return array If the search field GF Field type is `address`, and there are choices to add, adds them and changes the input type. Otherwise, sets the input to text. |
||
50 | */ |
||
51 | public function search_field_filter( $search_fields, $widget, $widget_args ) { |
||
87 | |||
88 | /** |
||
89 | * Get array of countries to use for the search choices |
||
90 | * |
||
91 | * @since 1.19.2 |
||
92 | * |
||
93 | * @see GF_Field_Address::get_countries() |
||
94 | * |
||
95 | * @param GF_Field_Address $address_field |
||
96 | * |
||
97 | * @return array Array of countries with `value` and `text` keys as the name of the country |
||
98 | */ |
||
99 | private function get_choices_country( $address_field ) { |
||
114 | |||
115 | /** |
||
116 | * Get array of states to use for the search choices |
||
117 | * |
||
118 | * @since 1.19.2 |
||
119 | * |
||
120 | * @uses GF_Field_Address::get_us_states() |
||
121 | * @uses GF_Field_Address::get_us_state_code() |
||
122 | * @uses GF_Field_Address::get_canadian_provinces() |
||
123 | * |
||
124 | * @param GF_Field_Address $address_field |
||
125 | * |
||
126 | * @return array Array of countries with `value` and `text` keys as the name of the country |
||
127 | */ |
||
128 | private function get_choices_state( $address_field ) { |
||
162 | |||
163 | /** |
||
164 | * Add the input types available for each custom search field type |
||
165 | * |
||
166 | * @since 1.19.2 |
||
167 | * |
||
168 | * @param array $input_types Array of input types as the keys (`select`, `radio`, `multiselect`, `input_text`) with a string or array of supported inputs as values |
||
169 | * |
||
170 | * @return array $input_types array, but |
||
171 | */ |
||
172 | public function input_types( $input_types ) { |
||
187 | |||
188 | /** |
||
189 | * Converts the custom input type (address) into the selected type |
||
190 | * |
||
191 | * @since 1.19.2 |
||
192 | * |
||
193 | * @param string $input_type Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
||
194 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
||
195 | * @param string|int|float $field_id ID of the field being processed |
||
196 | * |
||
197 | * @return string If the field ID matches an address field input, return those options {@see GravityView_Field_Address::input_types() }. Otherwise, original value is used. |
||
198 | */ |
||
199 | public function search_bar_input_type( $input_type, $field_type, $field_id ) { |
||
214 | |||
215 | /** |
||
216 | * Get a name for the input based on the input ID |
||
217 | * |
||
218 | * @since 1.19.2 |
||
219 | * |
||
220 | * @param int $input_id ID of the specific input for the address field |
||
221 | * |
||
222 | * @return false|string If the input ID matches a known address field input, returns a name for that input ("city", or "country"). Otherwise, returns false. |
||
223 | */ |
||
224 | private static function get_input_type_from_input_id( $input_id ) { |
||
252 | |||
253 | function field_options( $field_options, $template_id = '', $field_id = '', $context = '', $input_type = '' ) { |
||
276 | |||
277 | } |
||
278 | |||
280 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.