HTMLMultiSelectField: Fix OOUI\CheckboxMultiselectInputWidget to be infusable again
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 16 Nov 2017 10:51:19 +0000 (11:51 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 16 Nov 2017 10:51:58 +0000 (11:51 +0100)
Regression from 5a113417e5af9d0d0dbed63429649a9780784d45.

Bug: T180677
Change-Id: Id1b0ebe9d9a56a76d73deb2b4d17213ae5e45a04

includes/htmlform/fields/HTMLMultiSelectField.php

index 515166c..238b2b4 100644 (file)
@@ -132,13 +132,17 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        /**
         * 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
@@ -147,6 +151,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                        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
@@ -158,7 +163,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
                        );
                }
 
-               $out = '';
+               $out = [];
                foreach ( $optionsOouiSections as $sectionLabel => $optionsOoui ) {
                        $attr = [];
                        $attr['name'] = "{$this->mName}[]";
@@ -185,16 +190,22 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
 
                        $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 );
        }
 
        /**