Completed
Pull Request — master (#991)
by Zack
12:50 queued 09:33
created

edit_entry_fix_hidden_fields()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 28
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 28
ccs 0
cts 9
cp 0
crap 20
rs 8.5806
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 80.

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.

Loading history...
2
/**
3
 * @file class-gravityview-field-hidden.php
4
 * @package GravityView
5
 * @subpackage includes\fields
6
 */
7
8
class GravityView_Field_Hidden extends GravityView_Field {
9
10
	var $name = 'hidden';
0 ignored issues
show
Coding Style introduced by
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;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $is_searchable.

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...
13
14
	var $search_operators = array( 'contains', 'is', 'isnot', 'starts_with', 'ends_with' );
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $search_operators.

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...
15
16
	var $_gf_field_class_name = 'GF_Field_Hidden';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_gf_field_class_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...
17
18
	var $group = 'standard';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $group.

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...
19
20
	public function __construct() {
21
		$this->label = esc_html__( 'Hidden', 'gravityview' );
22
23
		$this->edit_entry_add_hooks();
24
25
		parent::__construct();
26
	}
27
28
	/**
29
	 * Add Edit Entry hooks
30
	 *
31
	 * @since 1.17
32
	 *
33
	 * @return void
34
	 */
35
	private function edit_entry_add_hooks() {
36
		add_filter( 'gravityview/edit_entry/form_fields', array( $this, 'edit_entry_fix_hidden_fields' ) );
37
	}
38
39
	/**
40
	 * Convert Hidden fields to be Text fields in Edit Entry
41
	 *
42
	 * @since 1.9.2
43
	 * @since 1.17 Moved to GravityView_Field_Hidden class
44
	 *
45
	 * @param GF_Field[] $fields Array of fields to be shown on the Edit Entry screen
46
	 *
47
	 * @return GF_Field[] Array of fields, with any hidden fields replaced with text fields
48
	 */
49
	function edit_entry_fix_hidden_fields( $fields ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
51
		/** @var GF_Field $field */
52
		foreach( $fields as &$field ) {
53
			if ( 'hidden' === $field->type ) {
54
55
				/**
56
				 * @filter `gravityview/edit_entry/reveal_hidden_field` Convert Hidden fields into Text fields on Edit Entry
57
				 * @since 1.22.6
58
				 * @param bool $reveal_hidden_field True: Convert the hidden field to text; False: Leave hidden
59
				 * @param GF_Field_Hidden $field The field in question
60
				 */
61
				$reveal_hidden_field = apply_filters( 'gravityview/edit_entry/reveal_hidden_field', true, $field );
62
63
				if( ! $reveal_hidden_field ) {
64
					continue;
65
				}
66
67
				// Replace GF_Field_Hidden with GF_Field_Text, copying all the data from $field
68
				$field = new GF_Field_Text( $field );
69
70
				// Everything is copied from $field, so we need to manually set the type
71
				$field->type = 'text';
72
			}
73
		}
74
75
		return $fields;
76
	}
77
78
}
79
80
new GravityView_Field_Hidden;
81