Completed
Push — master ( 9cf7be...029c15 )
by Zack
04:07
created

GravityView_Field_Post_Content::get_field_input()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 22

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 38
rs 8.8571
cc 1
eloc 22
nc 1
nop 4
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 86.

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-post-content.php
4
 * @package GravityView
5
 * @subpackage includes\fields
6
 */
7
8
class GravityView_Field_Post_Content extends GravityView_Field {
9
10
	var $name = 'post_content';
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 $search_operators = array( 'is', 'isnot', 'contains', '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...
13
14
	var $_gf_field_class_name = 'GF_Field_Post_Content';
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...
15
16
	var $group = 'post';
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...
17
18
	public function __construct() {
19
		$this->label = esc_html__( 'Post Content', 'gravityview' );
20
		parent::__construct();
21
	}
22
23
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
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...
24
25
		unset( $field_options['show_as_link'] );
26
27
		if( 'edit' === $context ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
28
			return $field_options;
29
		}
30
31
		$this->add_field_support('dynamic_data', $field_options );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
32
33
		return $field_options;
34
	}
35
36
	/**
37
	 * Returns the field inner markup.
38
	 *
39
	 * @param array $form The Form Object currently being processed.
40
	 * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
41
	 * @param null|array $entry Null or the Entry Object currently being edited.
42
	 *
43
	 * @return string
44
	 */
45
	public function get_field_input( $form, $value = '', $entry = null, GF_Field_Post_Content $field ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $entry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
47
		$id    = (int) $field->id;
48
		$input_name = "input_{$id}";
49
		$class = esc_attr( $field->size );
50
		$tabindex = $field->get_tabindex();
51
52
		$editor_settings = array(
53
			'editor_class'  => "textarea {$class}",
54
			'textarea_name' => $input_name,
55
			'textarea_rows' => 15,
56
			'tabindex'      => $tabindex,
57
			'media_buttons' => false,
58
			'quicktags' => false,
59
			'logic_event' => $field->get_conditional_logic_event( 'keyup' ),
60
			'placeholder' => $field->get_field_placeholder_attribute(),
61
		);
62
63
		/**
64
		 * @filter `gravityview/edit_entry/post_content/wp_editor_settings` Modify the settings passed to the Post Content wp_editor()
65
		 * @see wp_editor() For the options available
66
		 * @since 1.7
67
		 * @param array $editor_settings Array of settings to be passed to wp_editor(). Note: there are also two additional values in the array: `logic_event` and `placehodler`, added to the textarea HTML by GravityView.
68
		 */
69
		$editor_settings = apply_filters( 'gravityview/edit_entry/post_content/wp_editor_settings', $editor_settings );
70
71
		ob_start();
72
		wp_editor( $value, $input_name, $editor_settings );
73
		$editor = ob_get_clean();
74
75
		$logic_event = rgar( $editor_settings, 'logic_event' );
76
		$placeholder = rgar( $editor_settings, 'placeholder' );
77
78
		/** @internal Instead of using `add_filter('the_editor')` and doing the same thing, it's cleaner here. */
79
		$editor = str_replace( '<textarea ', "<textarea {$logic_event} {$placeholder}", $editor );
80
81
		return sprintf( "<div class='ginput_container ginput_container_post_content'>%s</div>", trim( $editor ) );
82
	}
83
84
}
85
86
new GravityView_Field_Post_Content;
87