/**
* Get the OOUI version of this field.
*
+ * Returns OOUI\CheckboxMultiselectInputWidget for fields that only have one section,
+ * string otherwise.
+ *
* @since 1.28
* @param string[] $value
- * @return OOUI\CheckboxMultiselectInputWidget
+ * @return string|OOUI\CheckboxMultiselectInputWidget
*/
public function getInputOOUI( $value ) {
$this->mParent->getOutput()->addModules( 'oojs-ui-widgets' );
+ $hasSections = false;
$optionsOouiSections = [];
$options = $this->getOptions();
// If the options are supposed to be split into sections, each section becomes a separate
if ( is_array( $section ) ) {
$optionsOouiSections[ $label ] = Xml::listDropDownOptionsOoui( $section );
unset( $options[$label] );
+ $hasSections = true;
}
}
// If anything remains in the array, they are sectionless options. Put them in a separate widget
);
}
- $out = '';
+ $out = [];
foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
$attr = [];
$attr['name'] = "{$this->mName}[]";
$widget = new OOUI\CheckboxMultiselectInputWidget( $attr );
if ( $sectionLabel ) {
- $out .= new OOUI\FieldsetLayout( [
+ $out[] = new OOUI\FieldsetLayout( [
'items' => [ $widget ],
'label' => $sectionLabel,
] );
} else {
- $out .= $widget;
+ $out[] = $widget;
}
}
- return $out;
+ if ( !$hasSections ) {
+ // Directly return the only OOUI\CheckboxMultiselectInputWidget.
+ // This allows it to be made infusable and later tweaked by JS code.
+ return $out[ 0 ];
+ }
+
+ return implode( '', $out );
}
/**