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 | var $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 | var $description; |
||
26 | |||
27 | /** |
||
28 | * @since 1.15.2 |
||
29 | * @type string The label of the field in the field picker |
||
30 | */ |
||
31 | var $label; |
||
32 | |||
33 | /** |
||
34 | * `standard`, `advanced`, `post`, `pricing`, `meta`, `gravityview` |
||
35 | * @internal Not yet implemented |
||
36 | * @since 1.15.2 |
||
37 | * @type string The group belongs to this field in the field picker |
||
38 | */ |
||
39 | var $group; |
||
40 | |||
41 | /** |
||
42 | * @internal Not yet implemented |
||
43 | * @type boolean Can the field be searched? |
||
44 | * @since 1.15.2 |
||
45 | */ |
||
46 | var $is_searchable; |
||
47 | |||
48 | /** |
||
49 | * @internal Not yet implemented |
||
50 | * @type array $search_operators The type of search operators available for this field |
||
51 | * @since 1.15.2 |
||
52 | */ |
||
53 | var $search_operators; |
||
54 | |||
55 | /** |
||
56 | * @type boolean Can the field be sorted in search? |
||
57 | * @since 1.15.2 |
||
58 | */ |
||
59 | var $is_sortable = true; |
||
60 | |||
61 | /** |
||
62 | * @type boolean Is field content number-based? |
||
63 | * @since 1.15.2 |
||
64 | */ |
||
65 | var $is_numeric; |
||
66 | |||
67 | /** |
||
68 | * @internal Not yet implemented |
||
69 | * @todo implement supports_context() method |
||
70 | * The contexts in which a field is available. Some fields aren't editable, for example. |
||
71 | * - `singular` is an alias for both `single` and `edit` |
||
72 | * - `multiple` is an alias for `directory` (backward compatibility) |
||
73 | * @type array |
||
74 | * @since 1.15.2 |
||
75 | */ |
||
76 | var $contexts = array( 'single', 'multiple', 'edit', 'export' ); |
||
77 | |||
78 | /** |
||
79 | * @internal Not yet implemented |
||
80 | * @since 1.15.2 |
||
81 | * @type string The name of a corresponding Gravity Forms GF_Field class, if exists |
||
82 | */ |
||
83 | protected $_gf_field_class_name; |
||
84 | |||
85 | /** |
||
86 | * @var string The field ID being requested |
||
87 | * @since 1.14 |
||
88 | */ |
||
89 | protected $_field_id = ''; |
||
90 | |||
91 | /** |
||
92 | * @var string Field options to be rendered |
||
93 | * @since 1.14 |
||
94 | */ |
||
95 | protected $_field_options = array(); |
||
96 | |||
97 | /** |
||
98 | * @var bool|string Name of merge tag (without curly brackets), if the field has custom GravityView merge tags to add. Otherwise, false. |
||
99 | * @since 1.16 |
||
100 | */ |
||
101 | protected $_custom_merge_tag = false; |
||
102 | |||
103 | function __construct() { |
||
126 | |||
127 | /** |
||
128 | * Match the merge tag in replacement text for the field. DO NOT OVERRIDE. |
||
129 | * |
||
130 | * @see replace_merge_tag Override replace_merge_tag() to handle any matches |
||
131 | * |
||
132 | * @since 1.16 |
||
133 | * |
||
134 | * @param string $text Text to replace |
||
135 | * @param array $form Gravity Forms form array |
||
136 | * @param array $entry Entry array |
||
137 | * @param bool $url_encode Whether to URL-encode output |
||
138 | * |
||
139 | * @return string Original text if {_custom_merge_tag} isn't found. Otherwise, replaced text. |
||
140 | */ |
||
141 | public function _filter_gform_replace_merge_tags( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) { |
||
163 | |||
164 | /** |
||
165 | * Run GravityView filters when using GFCommon::replace_variables() |
||
166 | * |
||
167 | * Instead of adding multiple hooks, add all hooks into this one method to improve speed |
||
168 | * |
||
169 | * @since 1.8.4 |
||
170 | * |
||
171 | * @param array $matches Array of Merge Tag matches found in text by preg_match_all |
||
172 | * @param string $text Text to replace |
||
173 | * @param array|bool $form Gravity Forms form array. When called inside {@see GFCommon::replace_variables()} (now deprecated), `false` |
||
174 | * @param array|bool $entry Entry array. When called inside {@see GFCommon::replace_variables()} (now deprecated), `false` |
||
175 | * @param bool $url_encode Whether to URL-encode output |
||
176 | * @param bool $esc_html Whether to apply `esc_html()` to output |
||
177 | * |
||
178 | * @return mixed |
||
179 | */ |
||
180 | public function replace_merge_tag( $matches = array(), $text = '', $form = array(), $entry = array(), $url_encode = false, $esc_html = false ) { |
||
197 | |||
198 | /** |
||
199 | * Add custom merge tags to merge tag options. DO NOT OVERRIDE. |
||
200 | * |
||
201 | * @internal Not to be overridden by fields |
||
202 | * |
||
203 | * @since 1.8.4 |
||
204 | * |
||
205 | * @param array $existing_merge_tags |
||
206 | * @param int $form_id GF Form ID |
||
207 | * @param GF_Field[] $fields Array of fields in the form |
||
208 | * @param string $element_id The ID of the input that Merge Tags are being used on |
||
209 | * |
||
210 | * @return array Modified merge tags |
||
211 | */ |
||
212 | public function _filter_gform_custom_merge_tags( $custom_merge_tags = array(), $form_id, $fields = array(), $element_id = '' ) { |
||
220 | |||
221 | /** |
||
222 | * Add custom Merge Tags to Merge Tag options, if custom Merge Tags exist |
||
223 | * |
||
224 | * Should be overridden if there's more than one Merge Tag to add or if the Merge Tag isn't {_custom_merge_tag} |
||
225 | * |
||
226 | * @since 1.16 |
||
227 | * |
||
228 | * @param array $form GF Form array |
||
229 | * @param GF_Field[] $fields Array of fields in the form |
||
230 | * |
||
231 | * @return array Merge tag array with `label` and `tag` keys based on class `label` and `_custom_merge_tag` variables |
||
232 | */ |
||
233 | protected function custom_merge_tags( $form = array(), $fields = array() ) { |
||
245 | |||
246 | /** |
||
247 | * Use field settings to modify whether a field is sortable |
||
248 | * |
||
249 | * @see GravityView_frontend::is_field_sortable |
||
250 | * @since 1.15.3 |
||
251 | * |
||
252 | * @param array $not_sortable Existing field types that aren't sortable |
||
253 | * |
||
254 | * @return array |
||
255 | */ |
||
256 | public function _filter_sortable_fields( $not_sortable ) { |
||
264 | |||
265 | private function field_support_options() { |
||
308 | |||
309 | function add_field_support( $key = '', &$field_options ) { |
||
319 | |||
320 | /** |
||
321 | * Tap in here to modify field options. |
||
322 | * |
||
323 | * Here's an example: |
||
324 | * |
||
325 | * <pre> |
||
326 | * $field_options['name_display'] = array( |
||
327 | * 'type' => 'select', |
||
328 | * 'label' => __( 'User Format', 'gravityview' ), |
||
329 | * 'desc' => __( 'How should the User information be displayed?', 'gravityview'), |
||
330 | * 'choices' => array( |
||
331 | * array( |
||
332 | * 'value' => 'display_name', |
||
333 | * 'label' => __('Display Name (Example: "Ellen Ripley")', 'gravityview'), |
||
334 | * ), |
||
335 | * array( |
||
336 | * 'value' => 'user_login', |
||
337 | * 'label' => __('Username (Example: "nostromo")', 'gravityview') |
||
338 | * ), |
||
339 | * 'value' => 'display_name' |
||
340 | * ); |
||
341 | * </pre> |
||
342 | * |
||
343 | * @param [type] $field_options [description] |
||
344 | * @param [type] $template_id [description] |
||
345 | * @param [type] $field_id [description] |
||
346 | * @param [type] $context [description] |
||
347 | * @param [type] $input_type [description] |
||
348 | * @return [type] [description] |
||
349 | */ |
||
350 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
||
357 | |||
358 | } |
||
359 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.