|
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'; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
var $search_operators = array( 'is', 'in', 'not in', 'isnot', 'contains'); |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
var $_gf_field_class_name = 'GF_Field_Checkbox'; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
var $group = 'standard'; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
public function __construct() { |
|
19
|
|
|
$this->label = esc_html__( 'Checkbox', 'gravityview' ); |
|
20
|
|
|
parent::__construct(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Add `choice_display` setting to the field |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $field_options |
|
27
|
|
|
* @param string $template_id |
|
28
|
|
|
* @param string $field_id |
|
29
|
|
|
* @param string $context |
|
30
|
|
|
* @param string $input_type |
|
31
|
|
|
* |
|
32
|
|
|
* @since 1.17 |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
// Set the $_field_id var |
|
39
|
|
|
$field_options = parent::field_options( $field_options, $template_id, $field_id, $context, $input_type ); |
|
40
|
|
|
|
|
41
|
|
|
// It's not the parent field; it's an input |
|
42
|
|
|
if( floor( $field_id ) !== floatval( $field_id ) ) { |
|
43
|
|
|
|
|
44
|
|
|
if( $this->is_choice_value_enabled() ) { |
|
45
|
|
|
$field_options['choice_display'] = array( |
|
46
|
|
|
'type' => 'radio', |
|
47
|
|
|
'value' => 'value', |
|
48
|
|
|
'class' => 'vertical', |
|
49
|
|
|
'label' => __( 'What should be displayed:', 'gravityview' ), |
|
50
|
|
|
'desc' => __( 'This input has a label and a value. What should be displayed?', 'gravityview' ), |
|
51
|
|
|
'choices' => array( |
|
52
|
|
|
'tick' => __( 'A check mark, if the input is checked', 'gravityview' ), |
|
53
|
|
|
'value' => __( 'Value of the input', 'gravityview' ), |
|
54
|
|
|
'label' => __( 'Label of the input', 'gravityview' ), |
|
55
|
|
|
), |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $field_options; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
new GravityView_Field_Checkbox; |
|
65
|
|
|
|
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.