HTMLForm: add errors to html in ooui variants
authorDerk-Jan Hartman <hartman.wiki@gmail.com>
Fri, 21 Apr 2017 12:50:53 +0000 (14:50 +0200)
committerTheDJ <hartman.wiki@gmail.com>
Fri, 21 Apr 2017 13:58:02 +0000 (13:58 +0000)
HTMLForm when using OOUI mode was not adding errors to the resulting
HTML, if depending on message arrays, as previously used before
Status.

This exposed additional problems. Aligned the function a bit closer to
HTMLForm's getErrorsOrWarnings()

Bug: T158492
Change-Id: I8765a025dd441676e35a7c183c67b37036643c1e

includes/htmlform/OOUIHTMLForm.php

index 549edde..6650321 100644 (file)
@@ -191,15 +191,12 @@ class OOUIHTMLForm extends HTMLForm {
         * @return string
         */
        public function getErrorsOrWarnings( $elements, $elementsType ) {
-               if ( !in_array( $elementsType, [ 'error', 'warning' ] ) ) {
+               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 +204,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 ) {