Merge "mw.htmlform: Fix hiding of the textbox for 'selectorother' fields on page...
[lhc/web/wiklou.git] / includes / htmlform / OOUIHTMLForm.php
index 54bdf04..ed99802 100644 (file)
@@ -191,15 +191,16 @@ class OOUIHTMLForm extends HTMLForm {
         * @return string
         */
        public function getErrorsOrWarnings( $elements, $elementsType ) {
-               if ( !in_array( $elementsType, [ 'error', 'warning' ] ) ) {
+               if ( $elements === '' ) {
+                       return '';
+               }
+
+               if ( !in_array( $elementsType, [ 'error', 'warning' ], true ) ) {
                        throw new DomainException( $elementsType . ' is not a valid type.' );
                }
-               if ( !$elements ) {
-                       $errors = [];
-               } elseif ( $elements instanceof Status ) {
-                       if ( $elements->isGood() ) {
-                               $errors = [];
-                       } else {
+               $errors = [];
+               if ( $elements instanceof Status ) {
+                       if ( !$elements->isGood() ) {
                                $errors = $elements->getErrorsByType( $elementsType );
                                foreach ( $errors as &$error ) {
                                        // Input:  [ 'message' => 'foo', 'errors' => [ 'a', 'b', 'c' ] ]
@@ -207,13 +208,12 @@ class OOUIHTMLForm extends HTMLForm {
                                        $error = array_merge( [ $error['message'] ], $error['params'] );
                                }
                        }
-               } elseif ( $elementsType === 'errors' )  {
-                       $errors = $elements;
-                       if ( !is_array( $errors ) ) {
-                               $errors = [ $errors ];
+               } elseif ( $elementsType === 'error' ) {
+                       if ( is_array( $elements ) ) {
+                               $errors = $elements;
+                       } elseif ( is_string( $elements ) ) {
+                               $errors = [ $elements ];
                        }
-               } else {
-                       $errors = [];
                }
 
                foreach ( $errors as &$error ) {