HTMLFormField: Don't display empty popup in OOUI mode if empty 'help' is given
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormField.php
index 3319d3b..d48e407 100644 (file)
@@ -61,7 +61,7 @@ abstract class HTMLFormField {
         * @return bool
         */
        public function canDisplayErrors() {
-               return true;
+               return $this->hasVisibleOutput();
        }
 
        /**
@@ -606,7 +606,7 @@ abstract class HTMLFormField {
                }
 
                $fieldType = get_class( $this );
-               $helpText = $this->getHelpText();
+               $help = $this->getHelpText();
                $errors = $this->getErrorsRaw( $value );
                foreach ( $errors as &$error ) {
                        $error = new OOUI\HtmlSnippet( $error );
@@ -620,14 +620,16 @@ abstract class HTMLFormField {
                $config = [
                        'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ],
                        'align' => $this->getLabelAlignOOUI(),
-                       'help' => $helpText !== null ? new OOUI\HtmlSnippet( $helpText ) : null,
+                       'help' => ( $help !== null && $help !== '' ) ? new OOUI\HtmlSnippet( $help ) : null,
                        'errors' => $errors,
                        'notices' => $notices,
                        'infusable' => $infusable,
                ];
 
+               $preloadModules = false;
+
                if ( $infusable && $this->shouldInfuseOOUI() ) {
-                       $this->mParent->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
+                       $preloadModules = true;
                        $config['classes'][] = 'mw-htmlform-field-autoinfuse';
                }
 
@@ -638,10 +640,17 @@ abstract class HTMLFormField {
                }
 
                if ( $this->mHideIf ) {
-                       $this->mParent->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
+                       $preloadModules = true;
                        $config['hideIf'] = $this->mHideIf;
                }
 
+               $config['modules'] = $this->getOOUIModules();
+
+               if ( $preloadModules ) {
+                       $this->mParent->getOutput()->addModules( 'mediawiki.htmlform.ooui' );
+                       $this->mParent->getOutput()->addModules( $this->getOOUIModules() );
+               }
+
                return $this->getFieldLayoutOOUI( $inputField, $config );
        }
 
@@ -677,6 +686,16 @@ abstract class HTMLFormField {
                return $this->getHelpText() !== null;
        }
 
+       /**
+        * Get the list of extra ResourceLoader modules which must be loaded client-side before it's
+        * possible to infuse this field's OOjs UI widget.
+        *
+        * @return string[]
+        */
+       protected function getOOUIModules() {
+               return [];
+       }
+
        /**
         * Get the complete raw fields for the input, including help text,
         * labels, and whatever.