GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class.render.settings.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Renders field/widget options and view settings
4  *
5  * @package GravityView
6  * @license GPL2+
7  * @author GravityView <[email protected]>
8  * @link http://gravityview.co
9  * @copyright Copyright 2014, Katz Web Services, Inc.
10  *
11  * @since 1.2
12  */
13 
15 
16  /**
17  * Get available field groups.
18  *
19  * @since 2.10
20  *
21  * @return array
22  */
23  public static function get_field_groups() {
24 
25  return array(
26  'field' => _x( 'Field', 'Denotes the name under which certain field settings are grouped', 'gk-gravityview' ),
27  'display' => _x( 'Display', 'Denotes the name under which certain field settings are grouped', 'gk-gravityview' ),
28  'label' => _x( 'Label', 'Denotes the name under which certain field settings are grouped', 'gk-gravityview' ),
29  'visibility' => _x( 'Visibility', 'Denotes the name under which certain field settings are grouped', 'gk-gravityview' ),
30  'advanced' => _x( 'Advanced', 'Denotes the name under which certain field settings are grouped', 'gk-gravityview' ),
31  'default' => _x( 'Default', 'Denotes the name under which certain field settings are grouped', 'gk-gravityview' ),
32  );
33  }
34 
35  /**
36  * Get the default options for a standard field.
37  *
38  * @since 2.10 added $grouped parameter
39  *
40  * @param string $field_type Type of field options to render (`field` or `widget`)
41  * @param string $template_id Layout slug (`default_table`, `default_list`, `datatables_table`, etc.
42  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
43  * @param string $context What context are we in? Example: `single` or `directory`
44  * @param string $input_type (textarea, list, select, etc.)
45  * @param int $form_id The form ID. @since develop
46  * @param bool $grouped Whether to group the field settings by `group` key
47  *
48  * @return array Array of field options with `label`, `value`, `type`, `default` keys
49  */
50  public static function get_default_field_options( $field_type, $template_id, $field_id, $context, $input_type, $form_id, $grouped = false ) {
51 
52  $field_options = array();
53 
54  $is_table_layout = preg_match( '/table/ism', $template_id );
55 
56  if( 'field' === $field_type ) {
57 
58  // Default options - fields
59  $field_options = array(
60  'show_label' => array(
61  'type' => 'checkbox',
62  'label' => __( 'Show Label', 'gk-gravityview' ),
63  'value' => ! empty ( $is_table_layout ),
64  'priority' => 1000,
65  'group' => 'label',
66  ),
67  'custom_label' => array(
68  'type' => 'text',
69  'label' => __( 'Custom Label:', 'gk-gravityview' ),
70  'value' => '',
71  'merge_tags' => true,
72  'class' => 'widefat',
73  'priority' => 1100,
74  'requires' => 'show_label',
75  'group' => 'label',
76  ),
77  'custom_class' => array(
78  'type' => 'text',
79  'label' => __( 'Custom CSS Class:', 'gk-gravityview' ),
80  'desc' => __( 'This class will be added to the field container', 'gk-gravityview' ),
81  'value' => '',
82  'merge_tags' => true,
83  'tooltip' => 'gv_css_merge_tags',
84  'class' => 'widefat code',
85  'priority' => 5000,
86  'group' => 'advanced',
87  ),
88  'only_loggedin' => array(
89  'type' => 'checkbox',
90  'label' => __( 'Make visible only to logged-in users?', 'gk-gravityview' ),
91  'value' => '',
92  'priority' => 4000,
93  'group' => 'visibility',
94  ),
95  'only_loggedin_cap' => array(
96  'type' => 'select',
97  'label' => __( 'Make visible for:', 'gk-gravityview' ),
98  'options' => self::get_cap_choices( $template_id, $field_id, $context, $input_type ),
99  'class' => 'widefat',
100  'value' => 'read',
101  'priority' => 4100,
102  'requires' => 'only_loggedin',
103  'group' => 'visibility',
104  ),
105  );
106 
107  // Match Table as well as DataTables
108  if( $is_table_layout && 'directory' === $context ) {
109  $field_options['width'] = array(
110  'type' => 'number',
111  'label' => __('Percent Width', 'gk-gravityview'),
112  'desc' => __( 'Leave blank for column width to be based on the field content.', 'gk-gravityview'),
113  'class' => 'code widefat',
114  'value' => '',
115  'priority' => 200,
116  'group' => 'display',
117  );
118  }
119 
120  }
121 
122  // Remove suffix ":" from the labels to standardize style. Using trim() instead of rtrim() for i18n.
123  foreach ( $field_options as $key => $field_option ) {
124  $field_options[ $key ]['label'] = trim( $field_option['label'], ':' );
125  }
126 
127  /**
128  * @filter `gravityview_template_{$field_type}_options` Filter the field options by field type. Filter names: `gravityview_template_field_options` and `gravityview_template_widget_options`
129  * @param array Array of field options with `label`, `value`, `type`, `default` keys
130  * @param string $template_id Table slug
131  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
132  * @param string $context What context are we in? Example: `single` or `directory`
133  * @param string $input_type (textarea, list, select, etc.)
134  * @param int $form_id The form ID. {@since 2.5}
135  */
136  $field_options = apply_filters( "gravityview_template_{$field_type}_options", $field_options, $template_id, $field_id, $context, $input_type, $form_id );
137 
138  /**
139  * @filter `gravityview_template_{$input_type}_options` Filter the field options by input type (`$input_type` examples: `textarea`, `list`, `select`, etc.)
140  * @param array Array of field options with `label`, `value`, `type`, `default` keys
141  * @param string $template_id Table slug
142  * @param float $field_id GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
143  * @param string $context What context are we in? Example: `single` or `directory`
144  * @param string $input_type (textarea, list, select, etc.)
145  * @param int $form_id The form ID. {@since 2.5}
146  */
147  $field_options = apply_filters( "gravityview_template_{$input_type}_options", $field_options, $template_id, $field_id, $context, $input_type, $form_id );
148 
149  if ( 'directory' === $context && isset( $field_options['show_as_link'] ) && ! isset( $field_options['new_window'] ) ) {
150  $field_options['new_window'] = array(
151  'type' => 'checkbox',
152  'label' => __( 'Open link in a new tab or window?', 'gk-gravityview' ),
153  'value' => false,
154  'context' => 'directory',
155  'requires' => 'show_as_link',
156  'priority' => 101,
157  'group' => 'display',
158  );
159  }
160 
161  if ( $grouped ) {
162 
163  $option_groups = array();
164 
165  foreach ( $field_options as $key => $field_option ) {
166 
167  // TODO: Add filter to override instead of doing inline.
168  switch ( $key ) {
169  case 'show_as_link':
170  $_group = 'display';
171  $field_option['priority'] = 100;
172  break;
173  default:
174  $_group = \GV\Utils::get( $field_option, 'group', 'display' );
175  break;
176  }
177 
178  $option_groups[ $_group ][ $key ] = $field_option;
179  }
180 
181  foreach ( $option_groups as & $option_group ) {
182  uasort( $option_group, array( __CLASS__, '_sort_by_priority' ) );
183  }
184 
185  $field_options = array();
186  foreach ( self::get_field_groups() as $group_key => $group_name ) {
187  $field_options[ $group_key ] = \GV\Utils::get( $option_groups, $group_key, array() );
188  }
189 
190  } else {
191  uasort( $field_options, array( __CLASS__, '_sort_by_priority' ) );
192  }
193 
194  return $field_options;
195  }
196 
197  /**
198  * Sort field settings by the `priority` key
199  *
200  * Default priority is 10001. Lower is higher.
201  *
202  * @since 3.0
203  * @internal
204  *
205  * @param array $a
206  * @param array $b
207  */
208  static public function _sort_by_priority( $a, $b ) {
209 
210  $a_priority = \GV\Utils::get( $a, 'priority', 10001 );
211  $b_priority = \GV\Utils::get( $b, 'priority', 10001 );
212 
213  if ( $a_priority === $b_priority ) {
214  return 0;
215  }
216 
217  return ( $a_priority < $b_priority ) ? - 1 : 1;
218  }
219 
220  /**
221  * Get capabilities options for GravityView
222  *
223  * Parameters are only to pass to the filter.
224  *
225  * @param string $template_id Optional. View slug
226  * @param string $field_id Optional. GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
227  * @param string $context Optional. What context are we in? Example: `single` or `directory`
228  * @param string $input_type Optional. (textarea, list, select, etc.)
229  * @return array Associative array, with the key being the capability and the value being the label shown.
230  */
231  static public function get_cap_choices( $template_id = '', $field_id = '', $context = '', $input_type = '' ) {
232 
233  $select_cap_choices = array(
234  'read' => __( 'Any Logged-In User', 'gk-gravityview' ),
235  'publish_posts' => __( 'Author Or Higher', 'gk-gravityview' ),
236  'gravityforms_view_entries' => __( 'Can View Gravity Forms Entries', 'gk-gravityview' ),
237  'delete_others_posts' => __( 'Editor Or Higher', 'gk-gravityview' ),
238  'gravityforms_edit_entries' => __( 'Can Edit Gravity Forms Entries', 'gk-gravityview' ),
239  'manage_options' => __( 'Administrator', 'gk-gravityview' ),
240  );
241 
242  if( is_multisite() ) {
243  $select_cap_choices['manage_network'] = __('Multisite Super Admin', 'gk-gravityview' );
244  }
245 
246  /**
247  * @filter `gravityview_field_visibility_caps` Modify the capabilities shown in the field dropdown
248  * @see https://docs.gravityview.co/article/96-how-to-modify-capabilities-shown-in-the-field-only-visible-to-dropdown
249  * @since 1.0.1
250  * @param array $select_cap_choices Associative rray of role slugs with labels ( `manage_options` => `Administrator` )
251  * @param string $template_id Optional. View slug
252  * @param string $field_id Optional. GF Field ID - Example: `3`, `5.2`, `entry_link`, `created_by`
253  * @param string $context Optional. What context are we in? Example: `single` or `directory`
254  * @param string $input_type Optional. (textarea, list, select, etc.)
255  */
256  $select_cap_choices = apply_filters('gravityview_field_visibility_caps', $select_cap_choices, $template_id, $field_id, $context, $input_type );
257 
258  return $select_cap_choices;
259  }
260 
261 
262  /**
263  * Render Field Options html (shown through a dialog box)
264  *
265  * @see GravityView_Ajax::get_field_options
266  * @see GravityView_Admin_Views::render_active_areas
267  *
268  * @param string $form_id
269  * @param string $field_type field / widget
270  * @param string $template_id
271  * @param string $field_id
272  * @param string $field_label
273  * @param string $area
274  * @param string $uniqid (default: '')
275  * @param string $current (default: '')
276  * @param string $context (default: 'single')
277  * @param array $item Field or widget array that's being rendered
278  *
279  * @return string HTML of dialog box
280  */
281  public static function render_field_options( $form_id, $field_type, $template_id, $field_id, $field_label, $area, $input_type = NULL, $uniqid = '', $current = '', $context = 'single', $item = array() ) {
282  if( empty( $uniqid ) ) {
283  //generate a unique field id
284  $uniqid = uniqid('', false);
285  }
286 
287  $grouped = ( 'field' === $field_type );
288 
289  // get field/widget options
290  $option_groups = self::get_default_field_options( $field_type, $template_id, $field_id, $context, $input_type, $form_id, $grouped );
291 
292  if( ! $grouped ) {
293  $option_groups = array( $option_groups );
294  }
295 
296  $option_groups = array_filter( $option_groups );
297 
298  // two different post arrays, depending of the field type
299  $name_prefix = $field_type .'s' .'['. $area .']['. $uniqid .']';
300 
301  // build output
302  $hidden_fields = '<input type="hidden" class="field-key" name="'. $name_prefix .'[id]" value="'. esc_attr( $field_id ) .'">';
303  $hidden_fields .= '<input type="hidden" class="field-label" name="'. $name_prefix .'[label]" value="'. esc_attr( $field_label ) .'">';
304 
305  $form_title = '';
306  if ( $form_id ) {
307  $hidden_fields .= '<input type="hidden" class="field-form-id" name="'. $name_prefix .'[form_id]" value="'. esc_attr( $form_id ) .'">';
309  $form_title = $form['title'];
310  }
311 
312  // If there are no options, return what we got.
313  if ( empty( $option_groups ) ) {
314  return $hidden_fields . '<!-- No Options -->'; // The HTML comment is here for checking if the output is empty in render_label()
315  }
316 
317  $settings_title = esc_attr( sprintf( __( '%s Settings', 'gk-gravityview' ) , strip_tags( html_entity_decode( $field_label ) ) ) );
318 
319  $field_details = '';
320 
321  // Get the pretty name for the input type
322  $gv_field = GravityView_Fields::get( $input_type );
323 
324  if( $gv_field ) {
325  $input_type_label = $gv_field->label;
326  } else {
327  $input_type_label = $input_type;
328  }
329 
330  $field_settings = '';
331  foreach ( $option_groups as $group_key => $option_group ) {
332 
333  if ( empty( $option_group ) ) {
334  continue;
335  }
336 
337  if ( $grouped ) {
338  $group_name = rgar( self::get_field_groups(), $group_key, '' );
339  $field_settings .= '<fieldset class="item-settings-group item-settings-group-' . esc_attr( $group_key ) . '">';
340  $field_settings .= '<legend>' . esc_attr( $group_name ) . '</legend>';
341  }
342 
343  foreach ( $option_group as $key => $option ) {
344 
345  $value = isset( $current[ $key ] ) ? $current[ $key ] : null;
346 
347  $field_output = self::render_field_option( $name_prefix . '[' . $key . ']', $option, $value );
348 
349  // The setting is empty
350  if ( empty( $field_output ) ) {
351  continue;
352  }
353 
354  $show_if = '';
355  if ( ! empty( $option['requires'] ) ) {
356  $show_if .= sprintf( ' data-requires="%s"', $option['requires'] );
357  }
358 
359  if ( ! empty( $option['requires_not'] ) ) {
360  $show_if .= sprintf( ' data-requires-not="%s"', $option['requires_not'] );
361  }
362 
363  switch ( $option['type'] ) {
364  // Hide hidden fields
365  case 'hidden':
366  $field_settings .= '<div class="gv-setting-container gv-setting-container-' . esc_attr( $key ) . ' screen-reader-text">' . $field_output . '</div>';
367  break;
368  default:
369  $field_settings .= '<div class="gv-setting-container gv-setting-container-' . esc_attr( $key ) . '" ' . $show_if . '>' . $field_output . '</div>';
370  }
371  }
372 
373  if ( $grouped ) {
374  $field_settings .= '</fieldset>';
375  }
376  }
377 
378  $item_details = '';
379  $subtitle = '';
380 
381  if( 'field' === $field_type ) {
382  $subtitle = ! empty( $item['subtitle'] ) ? '<div class="subtitle">' . $item['subtitle'] . '</div>' : '';
383 
384  $item_details .= '
385  <div class="gv-field-details--container">
386  <label class="gv-field-details--toggle">' . esc_html__( 'Field Details', 'gk-gravityview' ) .' <i class="dashicons dashicons-arrow-right"></i></label>
387  <section class="gv-field-details gv-field-details--closed">';
388 
389  if ( $field_id && is_numeric( $field_id ) ) {
390  $item_details .= '
391  <div class="gv-field-detail gv-field-detail--field">
392  <span class="gv-field-detail--label">' . esc_html__( 'Field ID', 'gk-gravityview' ) .'</span><span class="gv-field-detail--value">#{{field_id}}</span>
393  </div>';
394  }
395 
396  $item_details .= '
397  <div class="gv-field-detail gv-field-detail--type">
398  <span class="gv-field-detail--label">' . esc_html_x( 'Type', 'The type of field being configured (eg: "Single Line Text")', 'gk-gravityview' ) .'</span><span class="gv-field-detail--value">{{input_type_label}}</span>
399  </div>';
400 
401  if( $form_id ) {
402  $item_details .= '
403  <div class="gv-field-detail gv-field-detail--form">
404  <span class="gv-field-detail--label">' . esc_html__( 'Form', 'gk-gravityview' ) .'</span><span class="gv-field-detail--value">{{form_title}} (#{{form_id}})</span>
405  </div>';
406  }
407 
408  $item_details .= '
409  </section>
410  </div>';
411  } else {
412  $subtitle = ! empty( $item['subtitle'] ) ? '<div class="subtitle">' . $item['subtitle'] . '</div>' : '';
413  $widget_details_content = \GV\Utils::get( $item, 'description', '' );
414 
415  // Intentionally not escaping to allow HTML.
416  $item_details = '<div class="gv-field-details--container">' . wpautop( trim( $widget_details_content ) ) . '</div>';
417  }
418 
419 $template = <<<EOD
420  <div class="gv-dialog-options" title="{{settings_title}}">
421  {{item_details}}
422  {{subtitle}}
423  {{field_settings}}
424  {{hidden_fields}}
425  </div>
426 EOD;
427 
428  $output = $template;
429 
430  $replacements = array(
431  'settings_title',
432  'hidden_fields',
433  'subtitle',
434  'field_settings',
435  'item_details',
436  'input_type_label',
437  'field_id',
438  'form_title',
439  'form_id',
440  );
441 
442  foreach ( $replacements as $replacement ) {
443  if ( is_null( ${$replacement} ) ) {
444  continue;
445  }
446 
447  if ( $replacement === 'form_id' && strpos( $form_id, 'preset_' ) !== false ) {
448  // Form has not yet been created.
449  $output = str_replace( '#{{' . $replacement . '}}', esc_html__( 'Form Preset', $output, 'gk-gravityview' ), $output );
450 
451  continue;
452  }
453 
454  $output = str_replace( '{{' . $replacement . '}}', ${$replacement}, $output );
455  }
456 
457  return $output;
458 
459  }
460 
461 
462 
463  /**
464  * Handle rendering a field option form element
465  *
466  * @param string $name Input `name` attribute
467  * @param array $option Associative array of options. See the $defaults variable for available keys.
468  * @param mixed $curr_value Current value of option
469  * @return string HTML output of option
470  */
471  public static function render_field_option( $name = '', $option = array(), $curr_value = null ) {
472 
473  $output = '';
474 
475  /**
476  * @deprecated setting index 'default' was replaced by 'value'
477  * @see GravityView_FieldType::get_field_defaults
478  */
479  if( !empty( $option['default'] ) && empty( $option['value'] ) ) {
480  $option['value'] = $option['default'];
481  _deprecated_function( 'GravityView_FieldType::get_field_defaults', '1.1.7', '[value] instead of [default] when defining the setting '. $name .' details' );
482  }
483 
484  // prepare to render option field type
485  if( isset( $option['type'] ) ) {
486 
487  $type_class = self::load_type_class( $option );
488 
489  if( class_exists( $type_class ) ) {
490 
491  /** @type GravityView_FieldType $render_type */
492  $render_type = new $type_class( $name, $option, $curr_value );
493 
494  ob_start();
495 
496  $render_type->render_option();
497 
498  $output = ob_get_clean();
499 
500  /**
501  * @filter `gravityview/option/output/{option_type}` Modify the output for a GravityView setting.\n
502  * `$option_type` is the type of setting (`radio`, `text`, etc.)
503  * @param string $output field class name
504  * @param array $option option field data
505  */
506  $output = apply_filters( "gravityview/option/output/{$option['type']}" , $output, $option );
507  }
508 
509  } // isset option[type]
510 
511  return $output;
512  }
513 
514 
515 
516 
517 
518 
519  /**
520  * Output a table row for view settings
521  * @param string $key The key of the input
522  * @param array $current_settings Associative array of current settings to use as input values, if set. If not set, the defaults are used.
523  * @param string $override_input [description]
524  * @param string $name [description]
525  * @param string $id [description]
526  * @return void [description]
527  */
528  public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) {
529 
531 
532  // If the key doesn't exist, there's something wrong.
533  if ( ! $setting = $settings->get( $key ) ) {
534  return;
535  }
536 
537  /**
538  * @deprecated setting index 'name' was replaced by 'label'
539  * @see GravityView_FieldType::get_field_defaults
540  */
541  if( isset( $setting['name'] ) && empty( $setting['label'] ) ) {
542  $setting['label'] = $setting['name'];
543  _deprecated_function( 'GravityView_FieldType::get_field_defaults', '1.1.7', '[label] instead of [name] when defining the setting '. $key .' details' );
544  }
545 
546  $name = esc_attr( sprintf( $name, $key ) );
547  $setting['id'] = esc_attr( sprintf( $id, $key ) );
548  $setting['tooltip'] = 'gv_' . $key;
549 
550  // Use default if current setting isn't set.
551  $curr_value = isset( $current_settings[ $key ] ) ? $current_settings[ $key ] : $setting['value'];
552 
553  // default setting type = text
554  $setting['type'] = empty( $setting['type'] ) ? 'text' : $setting['type'];
555 
556  // merge tags
557  if( !isset( $setting['merge_tags'] ) ) {
558  if( $setting['type'] === 'text' ) {
559  $setting['merge_tags'] = true;
560  } else {
561  $setting['merge_tags'] = false;
562  }
563  }
564 
565  $output = '';
566 
567  // render the setting
568  $type_class = self::load_type_class( $setting );
569  if( class_exists( $type_class ) ) {
570  /** @type GravityView_FieldType $render_type */
571  $render_type = new $type_class( $name, $setting, $curr_value );
572  ob_start();
573  $render_type->render_setting( $override_input );
574  $output = ob_get_clean();
575  $output = str_replace( 'gv-merge-tag-support', 'merge-tag-support', $output );
576  }
577 
578  // Check if setting is specific for a template
579  if( !empty( $setting['show_in_template'] ) ) {
580  if( !is_array( $setting['show_in_template'] ) ) {
581  $setting['show_in_template'] = array( $setting['show_in_template'] );
582  }
583  $show_if = ' data-show-if="'. implode( ' ', $setting['show_in_template'] ).'"';
584  } else {
585  $show_if = '';
586  }
587 
588  if( ! empty( $setting['requires'] ) ) {
589  $show_if .= sprintf( ' data-requires="%s"', $setting['requires'] );
590  }
591 
592  if( ! empty( $setting['requires_not'] ) ) {
593  $show_if .= sprintf( ' data-requires-not="%s"', $setting['requires_not'] );
594  }
595 
596  // output
597  echo '<tr style="vertical-align: top;" '. $show_if .'>' . $output . '</tr>';
598 
599  }
600 
601 
602  /**
603  * Given a field type calculates the php class. If not found try to load it.
604  * @param array $field
605  * @return string type class name
606  */
607  public static function load_type_class( $field = NULL ) {
608 
609  if( empty( $field['type'] ) ) {
610  return NULL;
611  }
612 
613  /**
614  * @filter `gravityview/setting/class/{field_type}`
615  * @param string $class_suffix field class suffix; `GravityView_FieldType_{$class_suffix}`
616  * @param array $field field data
617  */
618  $type_class = apply_filters( "gravityview/setting/class/{$field['type']}", 'GravityView_FieldType_' . $field['type'], $field );
619 
620  if( class_exists( $type_class ) ) {
621  return $type_class;
622  }
623 
624  /**
625  * @filter `gravityview/setting/class_file/{field_type}`
626  * @param string $field_type_include_path field class file path
627  * @param array $field field data
628  */
629  $class_file = apply_filters( "gravityview/setting/class_file/{$field['type']}", GRAVITYVIEW_DIR . "includes/admin/field-types/type_{$field['type']}.php", $field );
630 
631  if( $class_file && file_exists( $class_file ) ) {
632  require_once( $class_file );
633  }
634 
635  return $type_class;
636  }
637 
638 
639 
640 
641 
642  /**
643  * @deprecated 1.2
644  * Render the HTML for a checkbox input to be used on the field & widgets options
645  * @param string $name , name attribute
646  * @param string $current current value
647  * @return string html tags
648  */
649  public static function render_checkbox_option( $name = '', $id = '', $current = '' ) {
650 
651  _deprecated_function( __METHOD__, '1.2', 'GravityView_FieldType_checkbox::render_input' );
652 
653  $output = '<input name="'. esc_attr( $name ) .'" type="hidden" value="0">';
654  $output .= '<input name="'. esc_attr( $name ) .'" id="'. esc_attr( $id ) .'" type="checkbox" value="1" '. checked( $current, '1', false ) .' >';
655 
656  return $output;
657  }
658 
659 
660  /**
661  * @deprecated 1.2
662  * Render the HTML for an input text to be used on the field & widgets options
663  * @param string $name Unique name of the field. Exampe: `fields[directory_list-title][5374ff6ab128b][custom_label]`
664  * @param string $current [current value]
665  * @param string $add_merge_tags Add merge tags to the input?
666  * @param array $args Field settings, including `class` key for CSS class
667  * @return string [html tags]
668  */
669  public static function render_text_option( $name = '', $id = '', $current = '', $add_merge_tags = NULL, $args = array() ) {
670 
671  _deprecated_function( __METHOD__, '1.2', 'GravityView_FieldType_text::render_input' );
672 
673  // Show the merge tags if the field is a list view
674  $is_list = ( preg_match( '/_list-/ism', $name ));
675 
676  // Or is a single entry view
677  $is_single = ( preg_match( '/single_/ism', $name ));
678  $show = ( $is_single || $is_list );
679 
680  $class = '';
681  // and $add_merge_tags is not false
682  if( $show && $add_merge_tags !== false || $add_merge_tags === 'force' ) {
683  $class = 'gv-merge-tag-support mt-position-right mt-hide_all_fields ';
684  }
685 
686  $class .= !empty( $args['class'] ) ? $args['class'] : 'widefat';
687  $type = !empty( $args['type'] ) ? $args['type'] : 'text';
688 
689  return '<input name="'. esc_attr( $name ) .'" id="'. esc_attr( $id ) .'" type="'.esc_attr($type).'" value="'. esc_attr( $current ) .'" class="'.esc_attr( $class ).'">';
690  }
691 
692  /**
693  * @deprecated 1.2
694  * Render the HTML for an textarea input to be used on the field & widgets options
695  * @param string $name Unique name of the field. Exampe: `fields[directory_list-title][5374ff6ab128b][custom_label]`
696  * @param string $current [current value]
697  * @param string|boolean $add_merge_tags Add merge tags to the input?
698  * @param array $args Field settings, including `class` key for CSS class
699  * @return string [html tags]
700  */
701  public static function render_textarea_option( $name = '', $id = '', $current = '', $add_merge_tags = NULL, $args = array() ) {
702 
703  _deprecated_function( __METHOD__, '1.2', 'GravityView_FieldType_textarea::render_input' );
704 
705  // Show the merge tags if the field is a list view
706  $is_list = ( preg_match( '/_list-/ism', $name ));
707 
708  // Or is a single entry view
709  $is_single = ( preg_match( '/single_/ism', $name ));
710  $show = ( $is_single || $is_list );
711 
712  $class = '';
713  // and $add_merge_tags is not false
714  if( $show && $add_merge_tags !== false || $add_merge_tags === 'force' ) {
715  $class = 'gv-merge-tag-support mt-position-right mt-hide_all_fields ';
716  }
717 
718  $class .= !empty( $args['class'] ) ? 'widefat '.$args['class'] : 'widefat';
719 
720  return '<textarea name="'. esc_attr( $name ) .'" id="'. esc_attr( $id ) .'" class="'.esc_attr( $class ).'">'. esc_textarea( $current ) .'</textarea>';
721  }
722 
723  /**
724  *
725  * Render the HTML for a select box to be used on the field & widgets options
726  * @deprecated 1.2
727  * @param string $name [name attribute]
728  * @param array $choices [select options]
729  * @param string $current [current value]
730  * @return string [html tags]
731  */
732  public static function render_select_option( $name = '', $id = '', $choices = array(), $current = '' ) {
733 
734  _deprecated_function( __METHOD__, '1.2', 'GravityView_FieldType_select::render_input' );
735 
736  $output = '<select name="'. $name .'" id="'. $id .'">';
737  foreach( $choices as $value => $label ) {
738  $output .= '<option value="'. esc_attr( $value ) .'" '. selected( $value, $current, false ) .'>'. esc_html( $label ) .'</option>';
739  }
740  $output .= '</select>';
741 
742  return $output;
743  }
744 
745 
746 }
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:49
static _sort_by_priority( $a, $b)
Sort field settings by the priority key.
static render_field_options( $form_id, $field_type, $template_id, $field_id, $field_label, $area, $input_type=NULL, $uniqid='', $current='', $context='single', $item=array())
Render Field Options html (shown through a dialog box)
static load_type_class( $field=NULL)
Given a field type calculates the php class.
static with_defaults( $detailed=false)
Retrieve an instance of the settings with default values.
static render_checkbox_option( $name='', $id='', $current='')
if(! isset( $gravityview)||empty( $gravityview->template)) $template
The entry loop for the list output.
static get( $field_name)
Alias for get_instance()
static render_setting_row( $key='', $current_settings=array(), $override_input=null, $name='template_settings[%s]', $id='gravityview_se_%s')
Output a table row for view settings.
$class
$field_settings['content']
Definition: custom.php:27
static get_default_field_options( $field_type, $template_id, $field_id, $context, $input_type, $form_id, $grouped=false)
Get the default options for a standard field.
if(gravityview() ->plugin->is_GF_25()) $form
static get_field_groups()
Get available field groups.
$current_settings
static render_textarea_option( $name='', $id='', $current='', $add_merge_tags=NULL, $args=array())
$gv_field
Definition: time.php:11
static get_form_or_form_template( $form_id=0)
Returns form object for existing form or a form template.
static render_field_option( $name='', $option=array(), $curr_value=null)
Handle rendering a field option form element.
if(empty( $created_by)) $form_id
static render_text_option( $name='', $id='', $current='', $add_merge_tags=NULL, $args=array())
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
static get_cap_choices( $template_id='', $field_id='', $context='', $input_type='')
Get capabilities options for GravityView.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
Definition: time.php:22
static render_select_option( $name='', $id='', $choices=array(), $current='')
Render the HTML for a select box to be used on the field & widgets options.