Bartosz Dziewoński has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/225107

Change subject: HTMLForm: Handle HTMLFormFieldWithButton subclasses in OOUI 
forms
......................................................................

HTMLForm: Handle HTMLFormFieldWithButton subclasses in OOUI forms

Example usages in:
* I47a8649208279a4090623a3088112fcff9abc4d3 (Special:Watchlist)
* I2b3524e61efc618aa2b7484134bba562d5f9011c (Special:Export)

Change-Id: I9050c4a09cbb841ad26ca01a25f706227e35e3be
Co-Authored-By: Florian <[email protected]>
Co-Authored-By: Bartosz Dziewoński <[email protected]>
---
M includes/htmlform/HTMLFormField.php
M includes/htmlform/HTMLFormFieldWithButton.php
2 files changed, 30 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/07/225107/1

diff --git a/includes/htmlform/HTMLFormField.php 
b/includes/htmlform/HTMLFormField.php
index e19273b..2aa10af 100644
--- a/includes/htmlform/HTMLFormField.php
+++ b/includes/htmlform/HTMLFormField.php
@@ -581,13 +581,14 @@
                }
 
                $fieldType = get_class( $this );
-               $field = new OOUI\FieldLayout( $inputField, array(
+               $config = array(
                        'classes' => array( "mw-htmlform-field-$fieldType", 
$this->mClass, $errorClass ),
                        'align' => $this->getLabelAlignOOUI(),
                        'label' => $this->getLabel(),
                        'help' => $this->getHelpText(),
                        'infusable' => $infusable,
-               ) );
+               );
+               $field = $this->getFieldLayoutOOUI( $inputField, $config );
 
                return $field . $errors;
        }
@@ -601,6 +602,18 @@
        }
 
        /**
+        * Get a FieldLayout (or subclass thereof) to wrap this field in when 
using OOUI output.
+        * @return OOUI\FieldLayout
+        */
+       protected function getFieldLayoutOOUI( $inputField, $config ) {
+               if ( isset( $this->mClassWithButton ) ) {
+                       $buttonWidget = $this->mClassWithButton->getInputOOUI( 
'' );
+                       return new OOUI\ActionFieldLayout( $inputField, 
$buttonWidget, $config );
+               }
+               return new OOUI\FieldLayout( $inputField, $config );
+       }
+
+       /**
         * Get the complete raw fields for the input, including help text,
         * labels, and whatever.
         * @since 1.20
diff --git a/includes/htmlform/HTMLFormFieldWithButton.php 
b/includes/htmlform/HTMLFormFieldWithButton.php
index 113bb4b..252be97 100644
--- a/includes/htmlform/HTMLFormFieldWithButton.php
+++ b/includes/htmlform/HTMLFormFieldWithButton.php
@@ -18,6 +18,9 @@
        /** @var string $mButtonType Value for the button in this field */
        protected $mButtonValue;
 
+       /** @var string $mButtonType Value for the button in this field */
+       protected $mButtonFlags = array( 'primary', 'progressive' );
+
        public function __construct( $info ) {
                if ( isset( $info['buttonclass'] ) ) {
                        $this->mButtonClass = $info['buttonclass'];
@@ -34,6 +37,9 @@
                if ( isset( $info['buttontype'] ) ) {
                        $this->mButtonType = $info['buttontype'];
                }
+               if ( isset( $info['buttonflags'] ) ) {
+                       $this->mButtonFlags = $info['buttonflags'];
+               }
                parent::__construct( $info );
        }
 
@@ -46,6 +52,15 @@
                return Html::input( $this->mButtonName, $this->mButtonValue, 
$this->mButtonType, $attr );
        }
 
+       public function getInputOOUI( $value ) {
+               return new OOUI\ButtonInputWidget( array(
+                       'label' => $this->mButtonValue,
+                       'type' => $this->mButtonType,
+                       'flags' => $this->mButtonFlags,
+                       'icon' => 'check',
+               ) );
+       }
+
        /**
         * Combines the passed element with a button.
         * @param String $element Element to combine the button with.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9050c4a09cbb841ad26ca01a25f706227e35e3be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>

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

Reply via email to