From e843da420393133438236558b084b80e05100f6a Mon Sep 17 00:00:00 2001 From: Glaisher Date: Sat, 28 May 2016 22:17:03 +0500 Subject: [PATCH] Allow providing 'notices' for OOUI HTMLForm fields 'notice', 'notice-message' and 'notice-messages' can be used as a parameter to the HTMLForm field to show the notices. Only added implementation for OOUI forms because I'm not sure what to do for others. Bug: T104423 Change-Id: I512f3936bc3335df1bdf76505cfc39da6be99bed --- includes/htmlform/HTMLForm.php | 5 +++++ includes/htmlform/HTMLFormField.php | 30 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index e891c9c832..7e6d74fbe9 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -71,6 +71,11 @@ * 'help-messages' -- array of message keys/objects. As above, each item can * be an array of msg key and then parameters. * Overwrites 'help'. + * 'notice' -- message text for a message to use as a notice in the field. + * Currently used by OOUI form fields only. + * 'notice-messages' -- array of message keys/objects to use for notice. + * Overrides 'notice'. + * 'notice-message' -- message key or object to use as a notice. * 'required' -- passed through to the object, indicating that it * is a required field. * 'size' -- the length of text fields diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 9f5e72838b..afbb7d5a8d 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -598,11 +598,17 @@ abstract class HTMLFormField { $error = new OOUI\HtmlSnippet( $error ); } + $notices = $this->getNotices(); + foreach ( $notices as &$notice ) { + $notice = new OOUI\HtmlSnippet( $notice ); + } + $config = [ 'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ], 'align' => $this->getLabelAlignOOUI(), 'help' => $helpText !== null ? new OOUI\HtmlSnippet( $helpText ) : null, 'errors' => $errors, + 'notices' => $notices, 'infusable' => $infusable, ]; @@ -840,6 +846,30 @@ abstract class HTMLFormField { return $errors; } + /** + * Determine notices to display for the field. + * + * @since 1.28 + * @return string[] + */ + function getNotices() { + $notices = []; + + if ( isset( $this->mParams['notice-message'] ) ) { + $notices[] = $this->getMessage( $this->mParams['notice-message'] )->parse(); + } + + if ( isset( $this->mParams['notice-messages'] ) ) { + foreach ( $this->mParams['notice-messages'] as $msg ) { + $notices[] = $this->getMessage( $msg )->parse(); + } + } elseif ( isset( $this->mParams['notice'] ) ) { + $notices[] = $this->mParams['notice']; + } + + return $notices; + } + /** * @return string HTML */ -- 2.20.1