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' );
91 if ( isset( $this->mParams[
'dropdown'] ) ) {
92 $this->mParent->getOutput()->addModules(
'jquery.chosen' );
112 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
114 foreach ( $options as $label => $info ) {
115 if ( is_array( $info ) ) {
116 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
120 'id' =>
"{$this->mID}-$info",
123 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
124 $thisAttribs[
'disabled'] =
'disabled';
126 $checked = in_array( $info, $value,
true );
128 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
130 $html .=
' ' . Html::rawElement(
132 [
'class' =>
'mw-htmlform-flatlist-item' ],
143 throw new RuntimeException( __METHOD__ .
' is not supported' );
145 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
147 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
149 call_user_func( $elementFunc,
151 [
'for' => $attribs[
'id'] ],
165 throw new RuntimeException( __METHOD__ .
' is not supported' );
181 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
184 $value = array_filter( $value,
'is_scalar' );
186 $hasSections =
false;
187 $optionsOouiSections = [];
191 foreach ( $options as $label => $section ) {
192 if ( is_array( $section ) ) {
193 $optionsOouiSections[ $label ] = Html::listDropdownOptionsOoui( $section );
194 unset( $options[$label] );
201 $optionsOouiSections = array_merge(
202 [
'' => Html::listDropdownOptionsOoui( $options ) ],
206 '@phan-var array[][] $optionsOouiSections';
209 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
211 $attr[
'name'] =
"{$this->mName}[]";
213 $attr[
'value'] = $value;
215 $options = $optionsOoui;
216 foreach ( $options as &$option ) {
217 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
219 if ( $this->mOptionsLabelsNotFromMessage ) {
220 foreach ( $options as &$option ) {
221 $option[
'label'] = new \OOUI\HtmlSnippet( $option[
'label'] );
225 $attr[
'options'] = $options;
227 $attr += \OOUI\Element::configFromHtmlAttributes(
231 if ( $this->mClass !==
'' ) {
235 $widget = new \OOUI\CheckboxMultiselectInputWidget( $attr );
236 if ( $sectionLabel ) {
237 $out[] = new \OOUI\FieldsetLayout( [
238 'items' => [ $widget ],
240 'label' =>
new \OOUI\HtmlSnippet( $sectionLabel ),
247 if ( !$hasSections && $out ) {
248 if ( $this->mPlaceholder ) {
249 $out[0]->setData( ( $out[0]->getData() ?: [] ) + [
250 'placeholder' => $this->mPlaceholder,
258 return implode(
'', $out );
268 $fromRequest = $request->getArray( $this->mName, [] );
288 return $this->mDefault ?? [];
298 $forcedOn = array_intersect( $this->mParams[
'disabled-options'], $this->
getDefault() );
301 foreach ( $options as $opt ) {
302 $res[
"$opt"] = in_array( $opt, $forcedOn,
true ) || in_array( $opt, $data,
true );
318class_alias( HTMLMultiSelectField::class,
'HTMLMultiSelectField' );
array $params
The job parameters.
Module of static functions for generating XML.