Completed
Push — milestone/2_0/react-ui ( 54c726...f44dc3 )
by
unknown
04:19
created

Date_Field::get_picker_options()   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
 * Date picker field class.
7
 */
8
class Date_Field extends Field {
9
10
	/**
11
	 * Picker options.
12
	 *
13
	 * @var array
14
	 */
15
	public $picker_options = array(
16
		'allowInput' => true,
17
		'dateFormat' => 'Y-m-d',
18
	);
19
20
	/**
21
	 * The storage format in variant that can be used by JavaScript.
22
	 *
23
	 * @var string
24
	 */
25
	protected $storage_format = 'Y-m-d';
26
27
	/**
28
	 * Returns an array that holds the field data, suitable for JSON representation.
29
	 *
30
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
31
	 * @return array
32
	 */
33
	public function to_json( $load ) {
34
		$field_data = parent::to_json( $load );
35
36
		$field_data = array_merge( $field_data, array(
37
			'storage_format' => $this->storage_format,
38
			'picker_options' => $this->picker_options,
39
		) );
40
41
		return $field_data;
42
	}
43
44
	/**
45
	 * Set datepicker options
46
	 */
47
	public function set_picker_options( $options ) {
48
		$this->picker_options = array_replace( $this->picker_options, $options );
49
		return $this;
50
	}
51
52
	/**
53
	 * Returns the picker options.
54
	 */
55
	public function get_picker_options() {
56
		return $this->picker_options;
57
	}
58
}
59