Go to the documentation of this file.
35 $missing = array_diff( self::$requiredParams, array_keys( $params ) );
39 parent::__construct( $params );
43 $rows = $this->mParams[
'rows'];
44 $columns = $this->mParams[
'columns'];
47 $p = parent::validate( $value, $alldata );
53 if ( !is_array( $value ) ) {
60 foreach ( $rows as $rowTag ) {
61 foreach ( $columns as $columnTag ) {
62 $validOptions[] = $columnTag .
'-' . $rowTag;
65 $validValues = array_intersect( $value, $validOptions );
66 if ( count( $validValues ) == count( $value ) ) {
69 return $this->
msg(
'htmlform-select-badoption' );
86 $rows = $this->mParams[
'rows'];
87 $columns = $this->mParams[
'columns'];
89 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
93 foreach ( $columns as $columnLabel => $columnTag ) {
99 $tooltipClass =
'mw-icon-question';
100 if ( isset( $this->mParams[
'tooltip-class'] ) ) {
101 $tooltipClass = $this->mParams[
'tooltip-class'];
105 foreach ( $rows as $rowLabel => $rowTag ) {
107 if ( isset( $this->mParams[
'tooltips'][$rowLabel] ) ) {
109 'class' =>
"mw-htmlform-tooltip $tooltipClass",
110 'title' => $this->mParams[
'tooltips'][$rowLabel],
111 'aria-label' => $this->mParams[
'tooltips'][$rowLabel]
113 $rowLabel .=
' ' .
Html::element(
'span', $tooltipAttribs,
'' );
116 foreach ( $columns as $columnTag ) {
117 $thisTag =
"$columnTag-$rowTag";
120 'id' =>
"{$this->mID}-$thisTag",
123 $checked = in_array( $thisTag, (array)$value,
true );
126 $thisAttribs[
'disabled'] = 1;
127 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-off';
130 $thisAttribs[
'disabled'] = 1;
131 $thisAttribs[
'class'] =
'checkmatrix-forced checkmatrix-forced-on';
147 [
'class' =>
'mw-htmlform-matrix' ],
154 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
158 'name' => $this->mName,
161 'rows' => $this->mParams[
'rows'],
162 'columns' => $this->mParams[
'columns'],
163 'tooltips' => $this->mParams[
'tooltips'] ?? [],
164 'forcedOff' => $this->mParams[
'force-options-off'] ?? [],
165 'forcedOn' => $this->mParams[
'force-options-on'] ?? [],
167 ] + OOUI\Element::configFromHtmlAttributes( $attribs )
172 $checkbox =
Xml::check(
"{$this->mName}[]", $checked, $attribs );
173 if ( $this->mParent->getConfig()->get(
'UseMediaWikiUIEverywhere' ) ) {
183 return isset( $this->mParams[
'force-options-off'] )
184 && in_array( $tag, $this->mParams[
'force-options-off'] );
188 return isset( $this->mParams[
'force-options-on'] )
189 && in_array( $tag, $this->mParams[
'force-options-on'] );
206 $fieldType = static::class;
208 $cellAttributes = [
'colspan' => 2 ];
211 $hideAttributes = [];
212 if ( $this->mHideIf ) {
214 $hideClass =
'mw-htmlform-hide-if';
221 [
'class' =>
'mw-input' ] + $cellAttributes,
222 $inputHtml .
"\n$errors"
226 [
'class' =>
"mw-htmlform-vertical-label $hideClass" ] + $hideAttributes,
229 [
'class' =>
"mw-htmlform-field-$fieldType {$this->mClass} $errorClass $hideClass" ] +
233 return $html . $helptext;
245 return $request->getArray( $this->mName, [] );
253 return $this->mDefault ?? [];
260 foreach ( $columns as $column ) {
261 foreach ( $rows as $row ) {
263 $thisTag =
"$column-$row";
265 $res[$thisTag] =
false;
267 $res[$thisTag] =
true;
269 $res[$thisTag] = in_array( $thisTag, $data );
278 return [
'mediawiki.widgets.CheckMatrixWidget' ];
shouldInfuseOOUI()
Whether the field should be automatically infused.
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
static closeElement( $element)
Returns "</$element>".
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
getTableRow( $value)
Get the complete table row for the input, including help text, labels, and whatever.
getOneCheckboxHTML( $checked, $attribs)
filterDataForSubmit( $data)
Support for separating multi-option preferences into multiple preferences Due to lack of array suppor...
loadDataFromRequest( $request)
getInputHTML( $value)
Build a table containing a matrix of checkbox options.
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
__construct( $params)
Initialise the object.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).