Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
HTMLToggleSwitchField | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
getInputOOUI | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
shouldInfuseOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOOUIModules | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | use MediaWiki\Widget\ToggleSwitchWidget; |
6 | |
7 | class HTMLToggleSwitchField extends HTMLCheckField { |
8 | |
9 | /** |
10 | * Get the OOUI version of this field. |
11 | * |
12 | * @since 1.41 |
13 | * @param string $value |
14 | * @return ToggleSwitchWidget |
15 | */ |
16 | public function getInputOOUI( $value ) { |
17 | if ( !empty( $this->mParams['invert'] ) ) { |
18 | $value = !$value; |
19 | } |
20 | |
21 | $attr = $this->getTooltipAndAccessKeyOOUI(); |
22 | $attr['id'] = $this->mID; |
23 | $attr['name'] = $this->mName; |
24 | |
25 | $attr += \OOUI\Element::configFromHtmlAttributes( |
26 | $this->getAttributes( [ 'disabled', 'tabindex' ] ) |
27 | ); |
28 | |
29 | if ( $this->mClass !== '' ) { |
30 | $attr['classes'] = [ $this->mClass ]; |
31 | } |
32 | |
33 | // For the underlaying CheckboxInputWidget |
34 | $attr['selected'] = $value; |
35 | $attr['value'] = '1'; |
36 | |
37 | return new ToggleSwitchWidget( $attr ); |
38 | } |
39 | |
40 | /** |
41 | * @inheritDoc |
42 | */ |
43 | protected function shouldInfuseOOUI() { |
44 | // Always infuse, as we want a toggle widget when JS is enabled. |
45 | return true; |
46 | } |
47 | |
48 | protected function getOOUIModules() { |
49 | return [ 'mediawiki.widgets.ToggleSwitchWidget' ]; |
50 | } |
51 | } |
52 | |
53 | /** @deprecated class alias since 1.42 */ |
54 | class_alias( HTMLToggleSwitchField::class, 'HTMLToggleSwitchField' ); |