20 private $mPlaceholder;
40 if ( !isset( $this->mParams[
'disabled-options'] ) ) {
41 $this->mParams[
'disabled-options'] = [];
44 if ( isset(
$params[
'dropdown'] ) ) {
45 $this->mClass .=
' mw-htmlform-dropdown';
46 if ( isset(
$params[
'placeholder'] ) ) {
47 $this->mPlaceholder =
$params[
'placeholder'];
48 } elseif ( isset(
$params[
'placeholder-message'] ) ) {
49 $this->mPlaceholder = $this->
msg(
$params[
'placeholder-message'] )->text();
53 if ( isset(
$params[
'flatlist'] ) ) {
54 $this->mClass .=
' mw-htmlform-flatlist';
63 $p = parent::validate( $value, $alldata );
69 if ( !is_array( $value ) ) {
74 $value = array_filter( $value,
'is_scalar' );
76 if ( isset( $this->mParams[
'max'] ) && ( count( $value ) > $this->mParams[
'max'] ) ) {
77 return $this->
msg(
'htmlform-multiselect-toomany', $this->mParams[
'max'] );
80 # If all options are valid, array_intersect of the valid options
81 # and the provided options will return the provided options.
84 $validValues = array_intersect( $value, $validOptions );
85 if ( count( $validValues ) == count( $value ) ) {
88 return $this->
msg(
'htmlform-select-badoption' );
114 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
116 foreach ( $options as $label => $info ) {
117 if ( is_array( $info ) ) {
118 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
122 'id' =>
"{$this->mID}-$info",
125 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
126 $thisAttribs[
'disabled'] =
'disabled';
128 $checked = in_array( $info, $value,
true );
130 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
132 $html .=
' ' . Html::rawElement(
134 [
'class' =>
'mw-htmlform-flatlist-item' ],
145 throw new RuntimeException( __METHOD__ .
' is not supported' );
147 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
149 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
151 call_user_func( $elementFunc,
153 [
'for' => $attribs[
'id'] ],
167 throw new RuntimeException( __METHOD__ .
' is not supported' );
183 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
186 $value = array_filter( $value,
'is_scalar' );
188 $hasSections =
false;
189 $optionsOouiSections = [];
193 foreach ( $options as $label => $section ) {
194 if ( is_array( $section ) ) {
195 $optionsOouiSections[ $label ] = Html::listDropdownOptionsOoui( $section );
196 unset( $options[$label] );
203 $optionsOouiSections = array_merge(
204 [
'' => Html::listDropdownOptionsOoui( $options ) ],
208 '@phan-var array[][] $optionsOouiSections';
211 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
213 $attr[
'name'] =
"{$this->mName}[]";
215 $attr[
'value'] = $value;
217 $options = $optionsOoui;
218 foreach ( $options as &$option ) {
219 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
221 if ( $this->mOptionsLabelsNotFromMessage ) {
222 foreach ( $options as &$option ) {
223 $option[
'label'] = new \OOUI\HtmlSnippet( $option[
'label'] );
227 $attr[
'options'] = $options;
229 $attr += \OOUI\Element::configFromHtmlAttributes(
233 if ( $this->mClass !==
'' ) {
237 $widget = new \OOUI\CheckboxMultiselectInputWidget( $attr );
238 if ( $sectionLabel ) {
239 $out[] = new \OOUI\FieldsetLayout( [
240 'items' => [ $widget ],
242 'label' =>
new \OOUI\HtmlSnippet( $sectionLabel ),
249 if ( !$hasSections && $out ) {
250 $firstFieldData = $out[0]->getData() ?: [];
251 if ( $this->mPlaceholder ) {
252 $firstFieldData[
'placeholder'] = $this->mPlaceholder;
254 if ( isset( $this->mParams[
'max'] ) ) {
255 $firstFieldData[
'tagLimit'] = $this->mParams[
'max'];
257 $out[0]->setData( $firstFieldData );
263 return implode(
'', $out );
273 $fromRequest = $request->getArray( $this->mName, [] );
293 return $this->mDefault ?? [];
303 $forcedOn = array_intersect( $this->mParams[
'disabled-options'], $this->
getDefault() );
306 foreach ( $options as $opt ) {
307 $res[
"$opt"] = in_array( $opt, $forcedOn,
true ) || in_array( $opt, $data,
true );
323class_alias( HTMLMultiSelectField::class,
'HTMLMultiSelectField' );
array $params
The job parameters.