jenkins-bot has submitted this change and it was merged.

Change subject: Allow providing 'notices' for OOUI HTMLForm fields
......................................................................


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
---
M includes/htmlform/HTMLForm.php
M includes/htmlform/HTMLFormField.php
2 files changed, 35 insertions(+), 0 deletions(-)

Approvals:
  Bartosz Dziewoński: Looks good to me, but someone else must approve
  Florianschmidtwelzow: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php
index e891c9c..7e6d74f 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 9f5e728..afbb7d5 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -598,11 +598,17 @@
                        $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,
                ];
 
@@ -841,6 +847,30 @@
        }
 
        /**
+        * 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
         */
        function getLabel() {

-- 
To view, visit https://gerrit.wikimedia.org/r/291522
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I512f3936bc3335df1bdf76505cfc39da6be99bed
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Glaisher <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to