Allow providing 'notices' for OOUI HTMLForm fields
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormField.php
index 9f5e728..afbb7d5 100644 (file)
@@ -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
         */