Completed
Push — develop ( 7592b8...3eb7c5 )
by Zack
14:44
created

fields/class-gravityview-field-checkbox.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @file class-gravityview-field-checkbox.php
4
 * @package GravityView
5
 * @subpackage includes\fields
6
 */
7
8
class GravityView_Field_Checkbox extends GravityView_Field {
9
10
	var $name = 'checkbox';
0 ignored issues
show
The visibility should be declared for property $name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	var $is_searchable = true;
13
14
	/**
15
	 * @see GFCommon::get_field_filter_settings Gravity Forms suggests checkboxes should just be "is"
16
	 * @var array
17
	 */
18
	var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains' );
19
20
	var $_gf_field_class_name = 'GF_Field_Checkbox';
21
22
	var $group = 'standard';
23
24
	public function __construct() {
25
		$this->label = esc_html__( 'Checkbox', 'gravityview' );
26
		parent::__construct();
27
	}
28
29
	/**
30
	 * Add `choice_display` setting to the field
31
	 * 
32
	 * @param array $field_options
33
	 * @param string $template_id
34
	 * @param string $field_id
35
	 * @param string $context
36
	 * @param string $input_type
37
	 *
38
	 * @since 1.17
39
	 *
40
	 * @return array
41
	 */
42
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
43
44
		// Set the $_field_id var
45
		$field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type );
46
47
		// It's not the parent field; it's an input
48
		if( floor( $field_id ) !== floatval( $field_id ) ) {
49
50
			if( $this->is_choice_value_enabled() ) {
51
52
				$desc = esc_html__( 'This input has a label and a value. What should be displayed?', 'gravityview' );
53
				$default = 'value';
54
				$choices = array(
55
					'tick' => __( 'A check mark, if the input is checked', 'gravityview' ),
56
					'value' => __( 'Value of the input', 'gravityview' ),
57
					'label' => __( 'Label of the input', 'gravityview' ),
58
				);
59
			} else {
60
				$desc = '';
61
				$default = 'tick';
62
				$choices = array(
63
					'tick' => __( 'A check mark, if the input is checked', 'gravityview' ),
64
					'label' => __( 'Label of the input', 'gravityview' ),
65
				);
66
			}
67
68
			$field_options['choice_display'] = array(
69
				'type'    => 'radio',
70
				'class'   => 'vertical',
71
				'label'   => __( 'What should be displayed:', 'gravityview' ),
72
				'value'   => $default,
73
				'desc'    => $desc,
74
				'choices' => $choices,
75
			);
76
		}
77
78
		return $field_options;
79
	}
80
}
81
82
new GravityView_Field_Checkbox;
83