From: Derk-Jan Hartman Date: Fri, 21 Apr 2017 12:50:53 +0000 (+0200) Subject: HTMLForm: add errors to html in ooui variants X-Git-Tag: 1.31.0-rc.0~3445 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/?a=commitdiff_plain;h=31886054895d729b92e22b5cb4e2b952ec22272d;p=lhc%2Fweb%2Fwiklou.git HTMLForm: add errors to html in ooui variants 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 --- diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index 549edde610..6650321633 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -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 ) {