Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLToggleSwitchField.php
blob1c0f68e11642d4663803f417ccfe9402799ea50c
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use MediaWiki\Widget\ToggleSwitchWidget;
7 class HTMLToggleSwitchField extends HTMLCheckField {
9 /**
10 * Get the OOUI version of this field.
12 * @since 1.41
13 * @param string $value
14 * @return ToggleSwitchWidget
16 public function getInputOOUI( $value ) {
17 if ( !empty( $this->mParams['invert'] ) ) {
18 $value = !$value;
21 $attr = $this->getTooltipAndAccessKeyOOUI();
22 $attr['id'] = $this->mID;
23 $attr['name'] = $this->mName;
25 $attr += \OOUI\Element::configFromHtmlAttributes(
26 $this->getAttributes( [ 'disabled', 'tabindex' ] )
29 if ( $this->mClass !== '' ) {
30 $attr['classes'] = [ $this->mClass ];
33 // For the underlaying CheckboxInputWidget
34 $attr['selected'] = $value;
35 $attr['value'] = '1';
37 return new ToggleSwitchWidget( $attr );
40 /**
41 * @inheritDoc
43 protected function shouldInfuseOOUI() {
44 // Always infuse, as we want a toggle widget when JS is enabled.
45 return true;
48 protected function getOOUIModules() {
49 return [ 'mediawiki.widgets.ToggleSwitchWidget' ];
53 /** @deprecated class alias since 1.42 */
54 class_alias( HTMLToggleSwitchField::class, 'HTMLToggleSwitchField' );