Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
HTMLHiddenField | |
0.00% |
0 / 19 |
|
0.00% |
0 / 9 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getHiddenFieldData | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getTableRow | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getDiv | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRaw | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCodex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getInputHTML | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
canDisplayErrors | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasVisibleOutput | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | use MediaWiki\HTMLForm\HTMLFormField; |
6 | |
7 | /* |
8 | * @stable to extend |
9 | */ |
10 | class HTMLHiddenField extends HTMLFormField { |
11 | /** @var bool */ |
12 | protected $outputAsDefault = true; |
13 | |
14 | /** |
15 | * @stable to call |
16 | * @inheritDoc |
17 | */ |
18 | public function __construct( $params ) { |
19 | parent::__construct( $params ); |
20 | |
21 | if ( isset( $this->mParams['output-as-default'] ) ) { |
22 | $this->outputAsDefault = (bool)$this->mParams['output-as-default']; |
23 | } |
24 | |
25 | # Per HTML5 spec, hidden fields cannot be 'required' |
26 | # https://www.w3.org/TR/html5/forms.html#hidden-state-%28type=hidden%29 |
27 | unset( $this->mParams['required'] ); |
28 | } |
29 | |
30 | public function getHiddenFieldData( $value ) { |
31 | $params = []; |
32 | if ( $this->mID ) { |
33 | $params['id'] = $this->mID; |
34 | } |
35 | |
36 | if ( $this->outputAsDefault ) { |
37 | $value = $this->mDefault; |
38 | } |
39 | |
40 | return [ $this->mName, $value, $params ]; |
41 | } |
42 | |
43 | public function getTableRow( $value ) { |
44 | [ $name, $value, $params ] = $this->getHiddenFieldData( $value ); |
45 | $this->mParent->addHiddenField( $name, $value, $params ); |
46 | return ''; |
47 | } |
48 | |
49 | /** |
50 | * @param string $value |
51 | * @return string |
52 | * @since 1.20 |
53 | */ |
54 | public function getDiv( $value ) { |
55 | return $this->getTableRow( $value ); |
56 | } |
57 | |
58 | /** |
59 | * @param string $value |
60 | * @return string |
61 | * @since 1.20 |
62 | */ |
63 | public function getRaw( $value ) { |
64 | return $this->getTableRow( $value ); |
65 | } |
66 | |
67 | public function getCodex( $value ) { |
68 | return $this->getTableRow( $value ); |
69 | } |
70 | |
71 | public function getInputHTML( $value ) { |
72 | return ''; |
73 | } |
74 | |
75 | public function canDisplayErrors() { |
76 | return false; |
77 | } |
78 | |
79 | public function hasVisibleOutput() { |
80 | return false; |
81 | } |
82 | } |
83 | |
84 | /** @deprecated class alias since 1.42 */ |
85 | class_alias( HTMLHiddenField::class, 'HTMLHiddenField' ); |