Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
DateTimeInputWidget | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
30 | |||
getJavaScriptClassName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConfig | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getInputElement | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Widget; |
4 | |
5 | use InvalidArgumentException; |
6 | use OOUI\InputWidget; |
7 | use OOUI\Tag; |
8 | |
9 | /** |
10 | * Date-time input widget. |
11 | * |
12 | * @copyright 2016 MediaWiki Widgets Team and others; see AUTHORS.txt |
13 | * @license MIT |
14 | */ |
15 | class DateTimeInputWidget extends InputWidget { |
16 | |
17 | /** @var string|null */ |
18 | protected $type = null; |
19 | /** @var string|null */ |
20 | protected $min = null; |
21 | /** @var string|null */ |
22 | protected $max = null; |
23 | /** @var bool|null */ |
24 | protected $clearable = null; |
25 | |
26 | /** |
27 | * @param array $config Configuration options |
28 | * - string $config['type'] 'date', 'time', or 'datetime' |
29 | * - string $config['min'] Minimum date, time, or datetime |
30 | * - string $config['max'] Maximum date, time, or datetime |
31 | * - bool $config['clearable'] Whether to provide for blanking the value. |
32 | */ |
33 | public function __construct( array $config = [] ) { |
34 | // We need $this->type set before calling the parent constructor |
35 | if ( !isset( $config['type'] ) ) { |
36 | throw new InvalidArgumentException( '$config[\'type\'] must be specified' ); |
37 | } |
38 | $this->type = $config['type']; |
39 | |
40 | parent::__construct( $config ); |
41 | |
42 | // Properties, which are ignored in PHP and just shipped back to JS |
43 | if ( isset( $config['min'] ) ) { |
44 | $this->min = $config['min']; |
45 | } |
46 | if ( isset( $config['max'] ) ) { |
47 | $this->max = $config['max']; |
48 | } |
49 | if ( isset( $config['clearable'] ) ) { |
50 | $this->clearable = $config['clearable']; |
51 | } |
52 | |
53 | // Initialization |
54 | $this->addClasses( [ 'mw-widgets-datetime-dateTimeInputWidget' ] ); |
55 | $this->appendContent( new PendingTextInputWidget() ); |
56 | } |
57 | |
58 | protected function getJavaScriptClassName() { |
59 | return 'mw.widgets.datetime.DateTimeInputWidget'; |
60 | } |
61 | |
62 | public function getConfig( &$config ) { |
63 | $config['type'] = $this->type; |
64 | if ( $this->min !== null ) { |
65 | $config['min'] = $this->min; |
66 | } |
67 | if ( $this->max !== null ) { |
68 | $config['max'] = $this->max; |
69 | } |
70 | if ( $this->clearable !== null ) { |
71 | $config['clearable'] = $this->clearable; |
72 | } |
73 | return parent::getConfig( $config ); |
74 | } |
75 | |
76 | protected function getInputElement( $config ) { |
77 | return ( new Tag( 'input' ) )->setAttributes( [ 'type' => $this->type ] ); |
78 | } |
79 | } |