Completed
Push — milestone/2_0/container-condit... ( 446b23...9b81fb )
by
unknown
04:50
created

Date_Field   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A to_json() 0 11 1
A admin_enqueue_scripts() 0 5 1
A set_picker_options() 0 4 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 type.
12
	 *
13
	 * @var string
14
	 */
15
	protected $picker_type = 'datepicker';
16
17
	/**
18
	 * Picker options.
19
	 *
20
	 * @var array
21
	 */
22
	public $picker_options = array(
23
		'dateFormat' => 'yy-mm-dd',
24
		'altFormat' => 'yy-mm-dd',
25
		'altInput' => true,
26
	);
27
28
	/**
29
	 * The storage format in variant that can be used by JavaScript.
30
	 *
31
	 * @var string
32
	 */
33
	protected $storage_format = 'YYYY-MM-DD';
34
35
	/**
36
	 * Returns an array that holds the field data, suitable for JSON representation.
37
	 *
38
	 * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
39
	 * @return array
40
	 */
41
	public function to_json( $load ) {
42
		$field_data = parent::to_json( $load );
43
44
		$field_data = array_merge( $field_data, array(
45
			'storage_format' => $this->storage_format,
46
			'picker_type' => $this->picker_type,
47
			'picker_options' => $this->picker_options,
48
		) );
49
50
		return $field_data;
51
	}
52
53
	/**
54
	 * Hook administration scripts and styles.
55
	 */
56
	public static function admin_enqueue_scripts() {
57
		wp_enqueue_script( 'jquery-ui-datepicker' );
58
59
		wp_enqueue_style( 'jquery-ui', '//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.min.css', array(), \Carbon_Fields\VERSION );
60
	}
61
62
	/**
63
	 * Set datepicker options
64
	 */
65
	public function set_picker_options( $options ) {
66
		$this->picker_options = array_replace( $this->picker_options, $options );
67
		return $this;
68
	}
69
}
70