From 3a9b6bff322c1e1c6a9bfcec2a1fa27b2335dd33 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 14 Mar 2016 00:11:42 +0100 Subject: [PATCH] Don't add label-elements for elements that doesn't have one Fix the OOUI field element implementation to conditionally add labels to the FieldLayout (only if the label isn't empty). Also add setShowEmptyLabel( false ) to HTMLButtonField (labels usually aren't set outside of the button, the button itself should have a label). Bug: T129821 Change-Id: I0499bb82245273519e77c80e78bc431588875a85 --- includes/htmlform/HTMLButtonField.php | 2 ++ includes/htmlform/HTMLFormField.php | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/htmlform/HTMLButtonField.php b/includes/htmlform/HTMLButtonField.php index 0b07765931..16417fc4b5 100644 --- a/includes/htmlform/HTMLButtonField.php +++ b/includes/htmlform/HTMLButtonField.php @@ -56,6 +56,8 @@ class HTMLButtonField extends HTMLFormField { $this->buttonLabel = $info['buttonlabel-raw']; } + $this->setShowEmptyLabel( false ); + parent::__construct( $info ); } diff --git a/includes/htmlform/HTMLFormField.php b/includes/htmlform/HTMLFormField.php index 6e5d6569f5..a9c76321d7 100644 --- a/includes/htmlform/HTMLFormField.php +++ b/includes/htmlform/HTMLFormField.php @@ -610,12 +610,17 @@ abstract class HTMLFormField { $config = [ 'classes' => [ "mw-htmlform-field-$fieldType", $this->mClass ], 'align' => $this->getLabelAlignOOUI(), - 'label' => new OOUI\HtmlSnippet( $this->getLabel() ), 'help' => $helpText !== null ? new OOUI\HtmlSnippet( $helpText ) : null, 'errors' => $errors, 'infusable' => $infusable, ]; + // the element could specify, that the label doesn't need to be added + $label = $this->getLabel(); + if ( $label ) { + $config['label'] = new OOUI\HtmlSnippet( $label ); + } + return $this->getFieldLayoutOOUI( $inputField, $config ); } -- 2.20.1