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

Date_Field   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set_picker_options() 0 4 1
A to_json() 0 10 1
A get_picker_options() 0 3 1
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