Completed
Pull Request — master (#180)
by
unknown
02:19
created

Text_Field::set_placeholder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
namespace Carbon_Fields\Field;
3
4
/**
5
 * Text field class.
6
 */
7
class Text_Field extends Field {
8
	// Input field type attribute value. Defaults to text. Available types: text, email, url, number, password
9
	public $field_type = 'text';
10
	public $placeholder;
11
12
	/**
13
	 * Underscore template of this field.
14
	 */
15
	public function template() {
16
		?>
17
		<input id="{{{ id }}}" type="{{{ field_type }}}" name="{{{ name }}}" value="{{ value }}" placeholder="{{ placeholder }}" class="regular-{{{ field_type }}}" />
18
		<?php
19
	}
20
21
	/**
22
	 * Change the type of the input
23
	 *
24
	 * @param string $type
25
	 */
26
	public function set_type( $type ) {
27
		$this->field_type = $type;
28
		return $this;
29
	}
30
31
	/**
32
	 * Set field placeholder text
33
	 *
34
	 * @param string $placeholder
35
	 * @return object $this
36
	 **/
37
	public function set_placeholder( $placeholder ) {
38
		$this->placeholder = $placeholder;
39
		return $this;
40
	}
41
42
	/**
43
	 * Returns an array that holds the field data, suitable for JSON representation.
44
	 * This data will be available in the Underscore template and the Backbone Model.
45
	 *
46
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
47
	 * @return array
48
	 */
49 View Code Duplication
	public function to_json( $load ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
		$field_data = parent::to_json( $load );
51
52
		$field_data = array_merge( $field_data, array(
53
			'placeholder' => $this->placeholder,
54
			'field_type' => $this->field_type
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
55
		) );
56
		return $field_data;
57
	}
58
59
}
60
?>
61