Completed
Push — milestone/2_0/react-ui ( 75a435...d33541 )
by
unknown
03:48
created

Html_Field::get_label()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Carbon_Fields\Field;
4
5
/**
6
 * HTML field class.
7
 * Allows to create a field that displays any HTML in a container.
8
 */
9
class Html_Field extends Field {
10
11
	/**
12
	 * HTML contents to display
13
	 * 
14
	 * @var string
15
	 */
16
	public $field_html = '';
17
18
	/**
19
	 * Set the field HTML or callback that returns the HTML.
20
	 * @param string|callable $callback_or_html HTML or callable that returns the HTML.
21
	 */
22
	public function set_html( $callback_or_html ) {
23
		if ( is_callable( $callback_or_html ) ) {
24
			$this->field_html = call_user_func( $callback_or_html );
25
		} else {
26
			$this->field_html = $callback_or_html;
27
		}
28
29
		return $this;
30
	}
31
32
	/**
33
	 * Returns an array that holds the field data, suitable for JSON representation.
34
	 *
35
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
36
	 * @return array
37
	 */
38
	public function to_json( $load ) {
39
		$field_data = parent::to_json( $load );
40
41
		$field_data = array_merge( $field_data, array(
42
			'html' => $this->field_html,
43
		) );
44
45
		return $field_data;
46
	}
47
48
	/**
49
	 * Whether this field is required.
50
	 * The HTML field is non-required by design.
51
	 *
52
	 * @return false
53
	 */
54
	public function is_required() {
55
		return false;
56
	}
57
58
	/**
59
	 * Load the field value.
60
	 * Skipped, no value to be loaded.
61
	 */
62
	public function load() {
63
		// skip;
64
	}
65
66
	/**
67
	 * Save the field value.
68
	 * Skipped, no value to be saved.
69
	 */
70
	public function save() {
71
		// skip;
72
	}
73
74
	/**
75
	 * Delete the field value.
76
	 * Skipped, no value to be deleted.
77
	 */
78
	public function delete() {
79
		// skip;
80
	}
81
}
82