20 private $mPlaceholder;
38 if ( !isset( $this->mParams[
'disabled-options'] ) ) {
39 $this->mParams[
'disabled-options'] = [];
42 if ( isset(
$params[
'dropdown'] ) ) {
43 $this->mClass .=
' mw-htmlform-dropdown';
44 if ( isset(
$params[
'placeholder'] ) ) {
45 $this->mPlaceholder =
$params[
'placeholder'];
46 } elseif ( isset(
$params[
'placeholder-message'] ) ) {
47 $this->mPlaceholder = $this->
msg(
$params[
'placeholder-message'] )->text();
51 if ( isset(
$params[
'flatlist'] ) ) {
52 $this->mClass .=
' mw-htmlform-flatlist';
61 $p = parent::validate( $value, $alldata );
67 if ( !is_array( $value ) ) {
72 $value = array_filter( $value,
'is_scalar' );
74 # If all options are valid, array_intersect of the valid options
75 # and the provided options will return the provided options.
78 $validValues = array_intersect( $value, $validOptions );
79 if ( count( $validValues ) == count( $value ) ) {
82 return $this->
msg(
'htmlform-select-badoption' );
108 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
110 foreach ( $options as $label => $info ) {
111 if ( is_array( $info ) ) {
112 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
116 'id' =>
"{$this->mID}-$info",
119 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
120 $thisAttribs[
'disabled'] =
'disabled';
122 $checked = in_array( $info, $value,
true );
124 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
126 $html .=
' ' . Html::rawElement(
128 [
'class' =>
'mw-htmlform-flatlist-item' ],
139 throw new RuntimeException( __METHOD__ .
' is not supported' );
141 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
143 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
145 call_user_func( $elementFunc,
147 [
'for' => $attribs[
'id'] ],
161 throw new RuntimeException( __METHOD__ .
' is not supported' );
177 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
180 $value = array_filter( $value,
'is_scalar' );
182 $hasSections =
false;
183 $optionsOouiSections = [];
187 foreach ( $options as $label => $section ) {
188 if ( is_array( $section ) ) {
189 $optionsOouiSections[ $label ] = Html::listDropdownOptionsOoui( $section );
190 unset( $options[$label] );
197 $optionsOouiSections = array_merge(
198 [
'' => Html::listDropdownOptionsOoui( $options ) ],
202 '@phan-var array[][] $optionsOouiSections';
205 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
207 $attr[
'name'] =
"{$this->mName}[]";
209 $attr[
'value'] = $value;
211 $options = $optionsOoui;
212 foreach ( $options as &$option ) {
213 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
215 if ( $this->mOptionsLabelsNotFromMessage ) {
216 foreach ( $options as &$option ) {
217 $option[
'label'] = new \OOUI\HtmlSnippet( $option[
'label'] );
221 $attr[
'options'] = $options;
223 $attr += \OOUI\Element::configFromHtmlAttributes(
227 if ( $this->mClass !==
'' ) {
231 $widget = new \OOUI\CheckboxMultiselectInputWidget( $attr );
232 if ( $sectionLabel ) {
233 $out[] = new \OOUI\FieldsetLayout( [
234 'items' => [ $widget ],
236 'label' =>
new \OOUI\HtmlSnippet( $sectionLabel ),
243 if ( !$hasSections && $out ) {
244 if ( $this->mPlaceholder ) {
245 $out[0]->setData( ( $out[0]->getData() ?: [] ) + [
246 'placeholder' => $this->mPlaceholder,
254 return implode(
'', $out );
264 $fromRequest = $request->getArray( $this->mName, [] );
284 return $this->mDefault ?? [];
294 $forcedOn = array_intersect( $this->mParams[
'disabled-options'], $this->
getDefault() );
297 foreach ( $options as $opt ) {
298 $res[
"$opt"] = in_array( $opt, $forcedOn,
true ) || in_array( $opt, $data,
true );
314class_alias( HTMLMultiSelectField::class,
'HTMLMultiSelectField' );
array $params
The job parameters.