HTMLForm: Allow to set the primary flag for submit buttons
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Thu, 23 Jul 2015 16:38:18 +0000 (18:38 +0200)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Thu, 23 Jul 2015 19:48:35 +0000 (21:48 +0200)
Currently, every submit button generated by HTMLForm itself (not via
the descriptor) doesn't have the primary flag and there is no (easy) way
to add it, although this generated submit button is most likely the primary
one.

Add a new function HTMLForm::setSubmitPrimary() to allow a form to set
add the primary flag to this submit button.

Change-Id: I3ce363f995389a87764edb586b4b64ab2b77b0db

includes/htmlform/HTMLForm.php
includes/htmlform/OOUIHTMLForm.php
includes/htmlform/VFormHTMLForm.php

index 47200d9..48cc828 100644 (file)
@@ -167,7 +167,7 @@ class HTMLForm extends ContextSource {
        protected $mFieldTree;
        protected $mShowReset = false;
        protected $mShowSubmit = true;
-       protected $mSubmitFlag = 'constructive';
+       protected $mSubmitFlags = array( 'constructive', 'primary' );
 
        protected $mSubmitCallback;
        protected $mValidationErrorMessage;
@@ -975,7 +975,10 @@ class HTMLForm extends ContextSource {
                        $attribs['class'] = array( 'mw-htmlform-submit' );
 
                        if ( $useMediaWikiUIEverywhere ) {
-                               array_push( $attribs['class'], 'mw-ui-button', 'mw-ui-' . $this->mSubmitFlag );
+                               foreach ( $this->mSubmitFlags as $flag ) {
+                                       array_push( $attribs['class'], 'mw-ui-' . $flag );
+                               }
+                               array_push( $attribs['class'], 'mw-ui-button' );
                        }
 
                        $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
@@ -1102,7 +1105,7 @@ class HTMLForm extends ContextSource {
         * @since 1.24
         */
        public function setSubmitDestructive() {
-               $this->mSubmitFlag = 'destructive';
+               $this->mSubmitFlags = array( 'destructive', 'primary' );
        }
 
        /**
@@ -1110,7 +1113,7 @@ class HTMLForm extends ContextSource {
         * @since 1.25
         */
        public function setSubmitProgressive() {
-               $this->mSubmitFlag = 'progressive';
+               $this->mSubmitFlags = array( 'progressive', 'primary' );
        }
 
        /**
index fe2f26e..eec13ee 100644 (file)
@@ -65,7 +65,7 @@ class OOUIHTMLForm extends HTMLForm {
                        $attribs['type'] = 'submit';
                        $attribs['label'] = $this->getSubmitText();
                        $attribs['value'] = $this->getSubmitText();
-                       $attribs['flags'] = array( $this->mSubmitFlag );
+                       $attribs['flags'] = $this->mSubmitFlags;
 
                        $buttons .= new OOUI\ButtonInputWidget( $attribs );
                }
index c544f16..3788379 100644 (file)
@@ -95,8 +95,10 @@ class VFormHTMLForm extends HTMLForm {
                        $attribs['class'] = array(
                                'mw-htmlform-submit',
                                'mw-ui-button mw-ui-big mw-ui-block',
-                               'mw-ui-' . $this->mSubmitFlag,
                        );
+                       foreach ( $this->mSubmitFlags as $flag ) {
+                               $attribs['class'][] = 'mw-ui-' . $flag;
+                       }
 
                        $buttons .= Xml::submitButton( $this->getSubmitText(), $attribs ) . "\n";
                }