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' ] );
92 $headerContents = Html::rawElement(
'td', [],
"\u{00A0}" );
93 foreach ( $columns as $columnLabel => $columnTag ) {
94 $headerContents .= Html::rawElement(
'th', [], $columnLabel );
96 $thead = Html::rawElement(
'tr', [],
"\n$headerContents\n" );
97 $tableContents .= Html::rawElement(
'thead', [],
"\n$thead\n" );
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,
'' );
115 $rowContents = Html::rawElement(
'td', [], $rowLabel );
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';
136 $rowContents .= Html::rawElement(
142 $tableContents .= Html::rawElement(
'tr', [],
"\n$rowContents\n" );
146 $html .= Html::rawElement(
'table',
147 [
'class' =>
'mw-htmlform-matrix' ],
148 Html::rawElement(
'tbody', [],
"\n$tableContents\n" ) ) .
"\n";
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' ) ) {
174 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
176 Html::element(
'label', [
'for' => $attribs[
'id'] ] ) .
177 Html::closeElement(
'div' );
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 ) {
213 $hideAttributes[
'data-hide-if'] = FormatJson::encode( $this->mHideIf );
214 $hideClass =
'mw-htmlform-hide-if';
219 $field = Html::rawElement(
221 [
'class' =>
'mw-input' ] + $cellAttributes,
222 $inputHtml .
"\n$errors"
225 $html = Html::rawElement(
'tr',
226 [
'class' =>
"mw-htmlform-vertical-label $hideClass" ] + $hideAttributes,
228 $html .= Html::rawElement(
'tr',
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' ];
A checkbox matrix Operates similarly to HTMLMultiSelectField, but instead of using an array of option...
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
getOneCheckboxHTML( $checked, $attribs)
shouldInfuseOOUI()
Whether the field should be automatically infused.
__construct( $params)
Initialise the object.
getInputHTML( $value)
Build a table containing a matrix of checkbox options.
getTableRow( $value)
Get the complete table row for the input, including help text, labels, and whatever.
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
loadDataFromRequest( $request)
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.
filterDataForSubmit( $data)
Support for separating multi-option preferences into multiple preferences Due to lack of array suppor...