50 parent::__construct( $config );
52 $this->name = $config[
'name'] ??
null;
53 $this->
id = $config[
'id'] ??
null;
56 $this->rows = $config[
'rows'] ?? [];
57 $this->columns = $config[
'columns'] ?? [];
58 $this->tooltips = $config[
'tooltips'] ?? [];
60 $this->values = $config[
'values'] ?? [];
62 $this->forcedOn = $config[
'forcedOn'] ?? [];
63 $this->forcedOff = $config[
'forcedOff'] ?? [];
66 $table = new \OOUI\Tag(
'table' );
67 $table->addClasses( [
'mw-htmlform-matrix mw-widget-checkMatrixWidget-matrix' ] );
68 $thead = new \OOUI\Tag(
'thead' );
69 $table->appendContent( $thead );
70 $tr = new \OOUI\Tag(
'tr' );
73 $tr->appendContent( $this->getCellTag(
"\u{00A0}" ) );
74 foreach ( $this->columns as $columnLabel => $columnTag ) {
76 $this->getCellTag(
new \OOUI\HtmlSnippet( $columnLabel ),
'th' )
79 $thead->appendContent( $tr );
82 $tbody = new \OOUI\Tag(
'tbody' );
83 $table->appendContent( $tbody );
84 foreach ( $this->rows as $rowLabel => $rowTag ) {
85 $tbody->appendContent(
86 $this->getTableRow( $rowLabel, $rowTag )
91 $this->addClasses( [
'mw-widget-checkMatrixWidget' ] );
92 $this->appendContent( $table );
103 private function getTableRow( $label, $tag ) {
104 $row = new \OOUI\Tag(
'tr' );
105 $tooltip = $this->getTooltip( $label );
106 $labelFieldConfig = $tooltip ? [
'help' => $tooltip ] : [];
108 $labelField = new \OOUI\FieldLayout(
111 'label' =>
new \OOUI\HtmlSnippet( $label ),
113 ] + $labelFieldConfig
115 $row->appendContent( $this->getCellTag( $labelField ) );
118 foreach ( $this->columns as $columnTag ) {
119 $thisTag =
"$columnTag-$tag";
122 $checkbox = new \OOUI\CheckboxInputWidget( [
124 'name' => $this->name ?
"{$this->name}[]" : null,
125 'id' => $this->id ?
"{$this->id}-$thisTag" : null,
126 'selected' => $this->isTagChecked( $thisTag ),
127 'disabled' => $this->isTagDisabled( $thisTag ),
130 $row->appendContent( $this->getCellTag( $checkbox ) );
142 private function getCellTag(
$content, $tagElement =
'td' ) {
143 $cell = new \OOUI\Tag( $tagElement );
155 private function isTagChecked( $tagName ) {
157 return in_array( $tagName, (array)$this->values,
true ) ||
159 in_array( $tagName, (array)$this->forcedOn,
true );
169 private function isTagDisabled( $tagName ) {
172 $this->isDisabled() ||
174 in_array( $tagName, (array)$this->forcedOn,
true ) ||
175 in_array( $tagName, (array)$this->forcedOff,
true )
185 private function getTooltip( $label ) {
186 return $this->tooltips[ $label ] ??
null;
190 return 'mw.widgets.CheckMatrixWidget';
204 return parent::getConfig( $config );