14 private $mPlaceholder;
29 parent::__construct( $params );
32 if ( !isset( $this->mParams[
'disabled-options'] ) ) {
33 $this->mParams[
'disabled-options'] = [];
36 if ( isset( $params[
'dropdown'] ) ) {
37 $this->mClass .=
' mw-htmlform-dropdown';
38 if ( isset( $params[
'placeholder'] ) ) {
39 $this->mPlaceholder = $params[
'placeholder'];
40 } elseif ( isset( $params[
'placeholder-message'] ) ) {
41 $this->mPlaceholder = $this->
msg( $params[
'placeholder-message'] )->text();
45 if ( isset( $params[
'flatlist'] ) ) {
46 $this->mClass .=
' mw-htmlform-flatlist';
55 $p = parent::validate( $value, $alldata );
61 if ( !is_array( $value ) ) {
66 $value = array_filter( $value,
'is_scalar' );
68 # If all options are valid, array_intersect of the valid options
69 # and the provided options will return the provided options.
72 $validValues = array_intersect( $value, $validOptions );
73 if ( count( $validValues ) == count( $value ) ) {
76 return $this->
msg(
'htmlform-select-badoption' );
85 if ( isset( $this->mParams[
'dropdown'] ) ) {
86 $this->mParent->getOutput()->addModules(
'jquery.chosen' );
106 $attribs = $this->
getAttributes( [
'disabled',
'tabindex' ] );
108 foreach ( $options as $label => $info ) {
109 if ( is_array( $info ) ) {
110 $html .= Html::rawElement(
'h1', [], $label ) .
"\n";
114 'id' =>
"{$this->mID}-$info",
117 if ( in_array( $info, $this->mParams[
'disabled-options'],
true ) ) {
118 $thisAttribs[
'disabled'] =
'disabled';
120 $checked = in_array( $info, $value,
true );
122 $checkbox = $this->
getOneCheckbox( $checked, $attribs + $thisAttribs, $label );
124 $html .=
' ' . Html::rawElement(
126 [
'class' =>
'mw-htmlform-flatlist-item' ],
137 throw new RuntimeException( __METHOD__ .
' is not supported' );
139 $elementFunc = [ Html::class, $this->mOptionsLabelsNotFromMessage ?
'rawElement' :
'element' ];
141 Xml::check(
"{$this->mName}[]", $checked, $attribs ) .
143 call_user_func( $elementFunc,
145 [
'for' => $attribs[
'id'] ],
148 if ( $this->mParent->getConfig()->get( MainConfigNames::UseMediaWikiUIEverywhere ) ) {
149 $checkbox = Html::openElement(
'div', [
'class' =>
'mw-ui-checkbox' ] ) .
151 Html::closeElement(
'div' );
164 throw new RuntimeException( __METHOD__ .
' is not supported' );
180 $this->mParent->getOutput()->addModules(
'oojs-ui-widgets' );
183 $value = array_filter( $value,
'is_scalar' );
185 $hasSections =
false;
186 $optionsOouiSections = [];
190 foreach ( $options as $label => $section ) {
191 if ( is_array( $section ) ) {
192 $optionsOouiSections[ $label ] = Xml::listDropDownOptionsOoui( $section );
193 unset( $options[$label] );
200 $optionsOouiSections = array_merge(
201 [
'' => Xml::listDropDownOptionsOoui( $options ) ],
205 '@phan-var array[][] $optionsOouiSections';
208 foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
210 $attr[
'name'] =
"{$this->mName}[]";
212 $attr[
'value'] = $value;
214 $options = $optionsOoui;
215 foreach ( $options as &$option ) {
216 $option[
'disabled'] = in_array( $option[
'data'], $this->mParams[
'disabled-options'],
true );
218 if ( $this->mOptionsLabelsNotFromMessage ) {
219 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 !==
'' ) {
232 $attr[
'classes'] = [ $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 );
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
needsLabel()
Should this field have a label, or is there no input element with the appropriate id for the label to...
getOneCheckbox( $checked, $attribs, $label)
filterDataForSubmit( $data)
Support for separating multi-option preferences into multiple preferences Due to lack of array suppor...
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getInputOOUI( $value)
Get the OOUI version of this field.
formatOptions( $options, $value)
getDefault()
to override mixed
getOptionsOOUI()
Get options and make them into arrays suitable for OOUI.
loadDataFromRequest( $request)
A class containing constants representing the names of configuration variables.