From 31886054895d729b92e22b5cb4e2b952ec22272d Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Fri, 21 Apr 2017 14:50:53 +0200 Subject: [PATCH] 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 --- includes/htmlform/OOUIHTMLForm.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) 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 ) { -- 2.20.1