diff options
author | Func <Funcer@outlook.com> | 2021-12-18 03:47:45 +0000 |
---|---|---|
committer | Bartosz DziewoĆski <matma.rex@gmail.com> | 2022-01-07 22:14:23 +0100 |
commit | 2f3b8a4c9b58c886419badc2004bc9c408f5a40b (patch) | |
tree | 37982f668848b60a8f1345f96816f58a61983948 /includes/htmlform/HTMLFormField.php | |
parent | 11c1cacf000d2e196369f294423529906b5d77fc (diff) | |
download | mediawikicore-2f3b8a4c9b58c886419badc2004bc9c408f5a40b.tar.gz mediawikicore-2f3b8a4c9b58c886419badc2004bc9c408f5a40b.zip |
Add cond-state classes in the server-side
There is only one use case of cond-state classes passed to the client-side, and it can be done more natively.
Change-Id: Ib6835bb334bd65c6176f0a5c3881b20265901af9
Diffstat (limited to 'includes/htmlform/HTMLFormField.php')
-rw-r--r-- | includes/htmlform/HTMLFormField.php | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 386d02cb5fe6..f5f57f6a7059 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -28,7 +28,8 @@ abstract class HTMLFormField { /** * @var array Array to hold params for 'hide-if' or 'disable-if' statements */ - protected $mCondState = [ 'class' => [] ]; + protected $mCondState = []; + protected $mCondStateClass = []; /** * @var bool If true will generate an empty div element with no label @@ -275,7 +276,7 @@ abstract class HTMLFormField { * @return bool */ public function isHidden( $alldata ) { - if ( !$this->mCondState['class'] || !isset( $this->mCondState['hide'] ) ) { + if ( !( $this->mCondState && isset( $this->mCondState['hide'] ) ) ) { return false; } @@ -469,13 +470,13 @@ abstract class HTMLFormField { if ( isset( $params['hide-if'] ) && $params['hide-if'] ) { $this->mCondState['hide'] = $params['hide-if']; - $this->mCondState['class'][] = 'mw-htmlform-hide-if'; + $this->mCondStateClass[] = 'mw-htmlform-hide-if'; } if ( !( isset( $params['disabled'] ) && $params['disabled'] ) && isset( $params['disable-if'] ) && $params['disable-if'] ) { $this->mCondState['disable'] = $params['disable-if']; - $this->mCondState['class'][] = 'mw-htmlform-disable-if'; + $this->mCondStateClass[] = 'mw-htmlform-disable-if'; } } @@ -512,9 +513,9 @@ abstract class HTMLFormField { $inputHtml . "\n$errors" ); - if ( $this->mCondState['class'] ) { + if ( $this->mCondState ) { $rowAttributes['data-cond-state'] = FormatJson::encode( $this->mCondState ); - $rowClasses .= implode( ' ', $this->mCondState['class'] ); + $rowClasses .= implode( ' ', $this->mCondStateClass ); } if ( $verticalLabel ) { @@ -577,9 +578,9 @@ abstract class HTMLFormField { $wrapperAttributes = [ 'class' => $divCssClasses, ]; - if ( $this->mCondState['class'] ) { + if ( $this->mCondState ) { $wrapperAttributes['data-cond-state'] = FormatJson::encode( $this->mCondState ); - $wrapperAttributes['class'] = array_merge( $wrapperAttributes['class'], $this->mCondState['class'] ); + $wrapperAttributes['class'] = array_merge( $wrapperAttributes['class'], $this->mCondStateClass ); } $html = Html::rawElement( 'div', $wrapperAttributes, $label . $field ); $html .= $helptext; @@ -643,6 +644,9 @@ abstract class HTMLFormField { $preloadModules = true; $config['classes'][] = 'mw-htmlform-autoinfuse'; } + if ( $this->mCondState ) { + $config['classes'] = array_merge( $config['classes'], $this->mCondStateClass ); + } // the element could specify, that the label doesn't need to be added $label = $this->getLabel(); @@ -650,7 +654,7 @@ abstract class HTMLFormField { $config['label'] = new OOUI\HtmlSnippet( $label ); } - if ( $this->mCondState['class'] ) { + if ( $this->mCondState ) { $preloadModules = true; $config['condState'] = $this->mCondState; } @@ -800,9 +804,9 @@ abstract class HTMLFormField { } $rowAttributes = []; - if ( $this->mCondState['class'] ) { + if ( $this->mCondState ) { $rowAttributes['data-cond-state'] = FormatJson::encode( $this->mCondState ); - $rowAttributes['class'] = $this->mCondState['class']; + $rowAttributes['class'] = $this->mCondStateClass; } $tdClasses = [ 'htmlform-tip' ]; @@ -834,9 +838,9 @@ abstract class HTMLFormField { if ( $this->mHelpClass !== false ) { $wrapperAttributes['class'][] = $this->mHelpClass; } - if ( $this->mCondState['class'] ) { + if ( $this->mCondState ) { $wrapperAttributes['data-cond-state'] = FormatJson::encode( $this->mCondState ); - $wrapperAttributes['class'] = array_merge( $wrapperAttributes['class'], $this->mCondState['class'] ); + $wrapperAttributes['class'] = array_merge( $wrapperAttributes['class'], $this->mCondStateClass ); } $div = Html::rawElement( 'div', $wrapperAttributes, $helptext ); @@ -1237,7 +1241,7 @@ abstract class HTMLFormField { * @since 1.29 */ public function needsJSForHtml5FormValidation() { - if ( $this->mCondState['class'] ) { + if ( $this->mCondState ) { // This is probably more restrictive than it needs to be, but better safe than sorry return true; } |