1 | <?php |
||
11 | abstract class GravityView_Field { |
||
12 | |||
13 | /** |
||
14 | * The name of the GravityView field type |
||
15 | * Example: `created_by`, `text`, `fileupload`, `address`, `entry_link` |
||
16 | * @var string |
||
17 | */ |
||
18 | public $name; |
||
19 | |||
20 | /** |
||
21 | * @internal Not yet implemented |
||
22 | * @since 1.15.2 |
||
23 | * @type string The description of the field in the field picker |
||
24 | */ |
||
25 | public $description; |
||
26 | |||
27 | /** |
||
28 | * @since 1.15.2 |
||
29 | * @type string The label of the field in the field picker |
||
30 | */ |
||
31 | public $label; |
||
32 | |||
33 | /** |
||
34 | * @var string The default search label used by the search widget, if not set |
||
35 | */ |
||
36 | public $default_search_label; |
||
37 | |||
38 | /** |
||
39 | * `standard`, `advanced`, `post`, `pricing`, `meta`, `gravityview` |
||
40 | * @since 1.15.2 |
||
41 | * @type string The group belongs to this field in the field picker |
||
42 | */ |
||
43 | public $group; |
||
44 | |||
45 | /** |
||
46 | * @internal Not yet implemented |
||
47 | * @type boolean Can the field be searched? |
||
48 | * @since 1.15.2 |
||
49 | */ |
||
50 | public $is_searchable = true; |
||
51 | |||
52 | /** |
||
53 | * @internal Not yet implemented |
||
54 | * @type array $search_operators The type of search operators available for this field |
||
55 | * @since 1.15.2 |
||
56 | */ |
||
57 | public $search_operators; |
||
58 | |||
59 | /** |
||
60 | * @type boolean Can the field be sorted in search? |
||
61 | * @since 1.15.2 |
||
62 | */ |
||
63 | public $is_sortable = true; |
||
64 | |||
65 | /** |
||
66 | * @type boolean Is field content number-based? |
||
67 | * @since 1.15.2 |
||
68 | */ |
||
69 | public $is_numeric; |
||
70 | |||
71 | /** |
||
72 | * @var null|string The key used to search and sort entry meta in Gravity Forms. Used if the field stores data as custom entry meta. |
||
73 | * @see https://www.gravityhelp.com/documentation/article/gform_entry_meta/ |
||
74 | * @since 1.19 |
||
75 | */ |
||
76 | public $entry_meta_key = null; |
||
77 | |||
78 | /** |
||
79 | * @var string|array Optional. The callback function after entry meta is updated, only used if $entry_meta_key is set. |
||
80 | * @see https://www.gravityhelp.com/documentation/article/gform_entry_meta/ |
||
81 | * @since 1.19 |
||
82 | */ |
||
83 | var $entry_meta_update_callback = null; |
||
84 | |||
85 | /** |
||
86 | * @var bool Whether to show meta when set to true automatically adds the column to the entry list, without having to edit and add the column for display |
||
87 | * @since 1.19 |
||
88 | */ |
||
89 | var $entry_meta_is_default_column = false; |
||
90 | |||
91 | /** |
||
92 | * @internal Not yet implemented |
||
93 | * @todo implement supports_context() method |
||
94 | * The contexts in which a field is available. Some fields aren't editable, for example. |
||
95 | * - `singular` is an alias for both `single` and `edit` |
||
96 | * - `multiple` is an alias for `directory` (backward compatibility) |
||
97 | * @type array |
||
98 | * @since 1.15.2 |
||
99 | */ |
||
100 | public $contexts = array( 'single', 'multiple', 'edit', 'export' ); |
||
101 | |||
102 | /** |
||
103 | * @since 1.15.2 |
||
104 | * @since 1.16.2.2 Changed access to public (previously, protected) |
||
105 | * @type string The name of a corresponding Gravity Forms GF_Field class, if exists |
||
106 | */ |
||
107 | public $_gf_field_class_name; |
||
108 | |||
109 | /** |
||
110 | * @var string The field ID being requested |
||
111 | * @since 1.14 |
||
112 | */ |
||
113 | protected $_field_id = ''; |
||
114 | |||
115 | /** |
||
116 | * @var string Field options to be rendered |
||
117 | * @since 1.14 |
||
118 | */ |
||
119 | protected $_field_options = array(); |
||
120 | |||
121 | /** |
||
122 | * @var bool|string Name of merge tag (without curly brackets), if the field has custom GravityView merge tags to add. Otherwise, false. |
||
123 | * @since 1.16 |
||
124 | */ |
||
125 | protected $_custom_merge_tag = false; |
||
126 | |||
127 | /** |
||
128 | * GravityView_Field constructor. |
||
129 | */ |
||
130 | public function __construct() { |
||
165 | |||
166 | /** |
||
167 | * Add the field to the Filter & Sort available fields |
||
168 | * |
||
169 | * @since 1.19 |
||
170 | * |
||
171 | * @param array $fields Sub-set of GF form fields that are sortable |
||
172 | * |
||
173 | * @return array Modified $fields array to include approval status in the sorting dropdown |
||
174 | */ |
||
175 | public function add_sortable_field( $fields ) { |
||
186 | |||
187 | /** |
||
188 | * Allow setting a default search label for search fields based on the field type |
||
189 | * |
||
190 | * Useful for entry meta "fields" that don't have Gravity Forms labels, like `created_by` |
||
191 | * |
||
192 | * @since 1.17.3 |
||
193 | * |
||
194 | * @param string $label Existing label text, sanitized. |
||
195 | * @param array $gf_field Gravity Forms field array, as returned by `GFFormsModel::get_field()` |
||
196 | * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
||
197 | * |
||
198 | * @return string |
||
199 | */ |
||
200 | 4 | function set_default_search_label( $label = '', $gf_field = null, $field = array() ) { |
|
208 | |||
209 | /** |
||
210 | * Match the merge tag in replacement text for the field. DO NOT OVERRIDE. |
||
211 | * |
||
212 | * @see replace_merge_tag Override replace_merge_tag() to handle any matches |
||
213 | * |
||
214 | * @since 1.16 |
||
215 | * |
||
216 | * @param string $text Text to replace |
||
217 | * @param array $form Gravity Forms form array |
||
218 | * @param array $entry Entry array |
||
219 | * @param bool $url_encode Whether to URL-encode output |
||
220 | * |
||
221 | * @return string Original text if {_custom_merge_tag} isn't found. Otherwise, replaced text. |
||
222 | */ |
||
223 | 49 | public function _filter_gform_replace_merge_tags( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) { |
|
235 | |||
236 | /** |
||
237 | * Run GravityView filters when using GFCommon::replace_variables() |
||
238 | * |
||
239 | * Instead of adding multiple hooks, add all hooks into this one method to improve speed |
||
240 | * |
||
241 | * @since 1.8.4 |
||
242 | * |
||
243 | * @see GFCommon::replace_variables() |
||
244 | * |
||
245 | * @param array $matches Array of Merge Tag matches found in text by preg_match_all |
||
246 | * @param string $text Text to replace |
||
247 | * @param array|bool $form Gravity Forms form array. When called inside {@see GFCommon::replace_variables()} (now deprecated), `false` |
||
248 | * @param array|bool $entry Entry array. When called inside {@see GFCommon::replace_variables()} (now deprecated), `false` |
||
249 | * @param bool $url_encode Whether to URL-encode output |
||
250 | * @param bool $esc_html Whether to apply `esc_html()` to output |
||
251 | * |
||
252 | * @return mixed |
||
253 | */ |
||
254 | 1 | public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) { |
|
280 | |||
281 | /** |
||
282 | * Add custom merge tags to merge tag options. DO NOT OVERRIDE. |
||
283 | * |
||
284 | * @internal Not to be overridden by fields |
||
285 | * |
||
286 | * @since 1.8.4 |
||
287 | * |
||
288 | * @param array $custom_merge_tags |
||
289 | * @param int $form_id GF Form ID |
||
290 | * @param GF_Field[] $fields Array of fields in the form |
||
291 | * @param string $element_id The ID of the input that Merge Tags are being used on |
||
292 | * |
||
293 | * @return array Modified merge tags |
||
294 | */ |
||
295 | public function _filter_gform_custom_merge_tags( $custom_merge_tags = array(), $form_id, $fields = array(), $element_id = '' ) { |
||
303 | |||
304 | /** |
||
305 | * Add custom Merge Tags to Merge Tag options, if custom Merge Tags exist |
||
306 | * |
||
307 | * Should be overridden if there's more than one Merge Tag to add or if the Merge Tag isn't {_custom_merge_tag} |
||
308 | * |
||
309 | * @since 1.16 |
||
310 | * |
||
311 | * @param array $form GF Form array |
||
312 | * @param GF_Field[] $fields Array of fields in the form |
||
313 | * |
||
314 | * @return array Merge tag array with `label` and `tag` keys based on class `label` and `_custom_merge_tag` variables |
||
315 | */ |
||
316 | protected function custom_merge_tags( $form = array(), $fields = array() ) { |
||
328 | |||
329 | /** |
||
330 | * Use field settings to modify whether a field is sortable |
||
331 | * |
||
332 | * @see GravityView_frontend::is_field_sortable |
||
333 | * @since 1.15.3 |
||
334 | * |
||
335 | * @param array $not_sortable Existing field types that aren't sortable |
||
336 | * |
||
337 | * @return array |
||
338 | */ |
||
339 | 1 | public function _filter_sortable_fields( $not_sortable ) { |
|
347 | |||
348 | /** |
||
349 | * Add the custom entry meta key to make it searchable and sortable |
||
350 | * |
||
351 | * @see https://www.gravityhelp.com/documentation/article/gform_entry_meta/ |
||
352 | * |
||
353 | * @param array $entry_meta Array of custom entry meta keys with associative arrays |
||
354 | * |
||
355 | * @return mixed |
||
356 | */ |
||
357 | 165 | function add_entry_meta( $entry_meta ) { |
|
379 | |||
380 | private function field_support_options() { |
||
430 | |||
431 | function add_field_support( $key, &$field_options ) { |
||
441 | |||
442 | /** |
||
443 | * Tap in here to modify field options. |
||
444 | * |
||
445 | * Here's an example: |
||
446 | * |
||
447 | * <pre> |
||
448 | * $field_options['name_display'] = array( |
||
449 | * 'type' => 'select', |
||
450 | * 'label' => __( 'User Format', 'gravityview' ), |
||
451 | * 'desc' => __( 'How should the User information be displayed?', 'gravityview'), |
||
452 | * 'choices' => array( |
||
453 | * array( |
||
454 | * 'value' => 'display_name', |
||
455 | * 'label' => __('Display Name (Example: "Ellen Ripley")', 'gravityview'), |
||
456 | * ), |
||
457 | * array( |
||
458 | * 'value' => 'user_login', |
||
459 | * 'label' => __('Username (Example: "nostromo")', 'gravityview') |
||
460 | * ), |
||
461 | * 'value' => 'display_name' |
||
462 | * ); |
||
463 | * </pre> |
||
464 | * |
||
465 | * @param array $field_options [description] |
||
466 | * @param string $template_id [description] |
||
467 | * @param string $field_id [description] |
||
468 | * @param string $context [description] |
||
469 | * @param string $input_type [description] |
||
470 | * @return array [description] |
||
471 | */ |
||
472 | public function field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id ) { |
||
479 | |||
480 | /** |
||
481 | * Check whether the `enableChoiceValue` flag is set for a GF field |
||
482 | * |
||
483 | * Gets the current form ID, gets the field at that ID, then checks for the enableChoiceValue value. |
||
484 | * |
||
485 | * @access protected |
||
486 | * |
||
487 | * @uses GFAPI::get_form |
||
488 | * |
||
489 | * @since 1.17 |
||
490 | * |
||
491 | * @return bool True: Enable Choice Value is active for field; False: not active, or form invalid, or form not found. |
||
492 | */ |
||
493 | protected function is_choice_value_enabled() { |
||
519 | |||
520 | } |
||
521 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: