MediaWiki REL1_40
HTMLCheckField.php
Go to the documentation of this file.
1<?php
2
5
12
17 public function getInputHTML( $value ) {
18 $useMediaWikiUIEverywhere = false;
19 if ( $this->mParent ) {
20 $useMediaWikiUIEverywhere = $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere );
21 }
22
23 if ( !empty( $this->mParams['invert'] ) ) {
24 $value = !$value;
25 }
26
27 $attr = $this->getTooltipAndAccessKey();
28 $attr['id'] = $this->mID;
29
30 $attr += $this->getAttributes( [ 'disabled', 'tabindex' ] );
31
32 if ( $this->mClass !== '' ) {
33 $attr['class'] = $this->mClass;
34 }
35
36 $attrLabel = [ 'for' => $this->mID ];
37 if ( isset( $attr['title'] ) ) {
38 // propagate tooltip to label
39 $attrLabel['title'] = $attr['title'];
40 }
41
42 $chkLabel = Xml::check( $this->mName, $value, $attr ) .
43 "\u{00A0}" .
44 Html::rawElement( 'label', $attrLabel, $this->mLabel );
45
46 if ( $useMediaWikiUIEverywhere || $this->mParent instanceof VFormHTMLForm ) {
47 $chkLabel = Html::rawElement(
48 'div',
49 [ 'class' => 'mw-ui-checkbox' ],
50 $chkLabel
51 );
52 }
53
54 return $chkLabel;
55 }
56
64 public function getInputOOUI( $value ) {
65 if ( !empty( $this->mParams['invert'] ) ) {
66 $value = !$value;
67 }
68
69 $attr = $this->getTooltipAndAccessKeyOOUI();
70 $attr['id'] = $this->mID;
71 $attr['name'] = $this->mName;
72
73 $attr += OOUI\Element::configFromHtmlAttributes(
74 $this->getAttributes( [ 'disabled', 'tabindex' ] )
75 );
76
77 if ( $this->mClass !== '' ) {
78 $attr['classes'] = [ $this->mClass ];
79 }
80
81 $attr['selected'] = $value;
82 $attr['value'] = '1'; // Nasty hack, but needed to make this work
83
84 return new OOUI\CheckboxInputWidget( $attr );
85 }
86
97 public function getLabel() {
98 if ( $this->mParent instanceof OOUIHTMLForm ) {
99 return $this->mLabel;
100 } elseif (
101 $this->mParent instanceof HTMLForm &&
102 $this->mParent->getDisplayFormat() === 'div'
103 ) {
104 return '';
105 } else {
106 return "\u{00A0}";
107 }
108 }
109
115 protected function getLabelAlignOOUI() {
116 return 'inline';
117 }
118
124 protected function needsLabel() {
125 return false;
126 }
127
131 public function getDefault() {
132 return (bool)$this->mDefault;
133 }
134
141 public function loadDataFromRequest( $request ) {
142 $invert = isset( $this->mParams['invert'] ) && $this->mParams['invert'];
143
144 // Fetch the value in either one of the two following case:
145 // - we have a valid submit attempt (form was just submitted)
146 // - we have a value (an URL manually built by the user, or GET form with no wpFormIdentifier)
147 if ( $this->isSubmitAttempt( $request ) || $request->getCheck( $this->mName ) ) {
148 return $invert
149 ? !$request->getBool( $this->mName )
150 : $request->getBool( $this->mName );
151 } else {
152 return $this->getDefault();
153 }
154 }
155}
A checkbox field.
getLabel()
For a checkbox, the label goes on the right hand side, and is added in getInputHTML(),...
loadDataFromRequest( $request)
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getLabelAlignOOUI()
Get label alignment when generating field for OOUI.
getInputOOUI( $value)
Get the OOUI version of this field.
needsLabel()
checkboxes don't need a label.
The parent class to generate form fields.
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
isSubmitAttempt(WebRequest $request)
Can we assume that the request is an attempt to submit a HTMLForm, as opposed to an attempt to just v...
getAttributes(array $list)
Returns the given attributes from the parameters.
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:153
getDisplayFormat()
Getter for displayFormat.
Definition HTMLForm.php:503
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
A class containing constants representing the names of configuration variables.
Compact stacked vertical format for forms, implemented using OOUI widgets.
Compact stacked vertical format for forms.