Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
HTMLExpiryField | |
0.00% |
0 / 26 |
|
0.00% |
0 / 8 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getInputHTML | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
shouldInfuseOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOOUIModules | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getInputOOUI | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
getInputCodex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
loadDataFromRequest | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFieldByType | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | use MediaWiki\HTMLForm\HTMLForm; |
6 | use MediaWiki\HTMLForm\HTMLFormField; |
7 | use MediaWiki\Widget\ExpiryInputWidget; |
8 | |
9 | /** |
10 | * Expiry Field that allows the user to specify a precise date or a |
11 | * relative date string. |
12 | * |
13 | * @stable to extend |
14 | */ |
15 | class HTMLExpiryField extends HTMLFormField { |
16 | |
17 | /** |
18 | * @var HTMLFormField |
19 | */ |
20 | protected $relativeField; |
21 | |
22 | /** |
23 | * Relative Date Time Field. |
24 | * |
25 | * @stable to call |
26 | * @param array $params |
27 | */ |
28 | public function __construct( array $params = [] ) { |
29 | parent::__construct( $params ); |
30 | |
31 | $type = !empty( $params['options'] ) ? 'selectorother' : 'text'; |
32 | $this->relativeField = $this->getFieldByType( $type ); |
33 | } |
34 | |
35 | /** |
36 | * @inheritDoc |
37 | * |
38 | * Use whatever the relative field is as the standard HTML input. |
39 | */ |
40 | public function getInputHTML( $value ) { |
41 | return $this->relativeField->getInputHTML( $value ); |
42 | } |
43 | |
44 | protected function shouldInfuseOOUI() { |
45 | return true; |
46 | } |
47 | |
48 | /** |
49 | * @inheritDoc |
50 | */ |
51 | protected function getOOUIModules() { |
52 | return array_merge( |
53 | [ |
54 | 'mediawiki.widgets.expiry', |
55 | ], |
56 | $this->relativeField->getOOUIModules() |
57 | ); |
58 | } |
59 | |
60 | /** |
61 | * @inheritDoc |
62 | */ |
63 | public function getInputOOUI( $value ) { |
64 | return new ExpiryInputWidget( |
65 | $this->relativeField->getInputOOUI( $value ), |
66 | [ |
67 | 'id' => $this->mID, |
68 | 'required' => $this->mParams['required'] ?? false, |
69 | ] |
70 | ); |
71 | } |
72 | |
73 | public function getInputCodex( $value, $hasErrors ) { |
74 | return $this->relativeField->getInputCodex( $value, $hasErrors ); |
75 | } |
76 | |
77 | /** |
78 | * @inheritDoc |
79 | */ |
80 | public function loadDataFromRequest( $request ) { |
81 | return $this->relativeField->loadDataFromRequest( $request ); |
82 | } |
83 | |
84 | /** |
85 | * Get the HTMLForm field by the type string. |
86 | * |
87 | * @param string $type |
88 | * @return HTMLFormField |
89 | */ |
90 | protected function getFieldByType( $type ) { |
91 | $class = HTMLForm::$typeMappings[$type]; |
92 | $params = $this->mParams; |
93 | $params['type'] = $type; |
94 | $params['class'] = $class; |
95 | |
96 | // Remove Parameters that are being used on the parent. |
97 | unset( $params['label-message'] ); |
98 | return new $class( $params ); |
99 | } |
100 | |
101 | } |
102 | |
103 | /** @deprecated class alias since 1.42 */ |
104 | class_alias( HTMLExpiryField::class, 'HTMLExpiryField' ); |