From: Mark Holmquist Date: Tue, 16 Jul 2013 03:51:08 +0000 (-0700) Subject: Don't display empty preference sections X-Git-Tag: 1.31.0-rc.0~18971 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=d51f688f81b4daef4aa585cb4a839f57a58ce717;p=lhc%2Fweb%2Fwiklou.git Don't display empty preference sections If a preference section has only hidden or API preferences, there are no contents. So it would be silly to display a section heading for it, since the user cannot see anything inside. Change-Id: Ia1d89032c45a06c5103e50d90f3ef147213dd571 --- diff --git a/includes/HTMLForm.php b/includes/HTMLForm.php index e06a934d76..84e7874d6e 100644 --- a/includes/HTMLForm.php +++ b/includes/HTMLForm.php @@ -968,9 +968,10 @@ class HTMLForm extends ContextSource { * @param $fields array[]|HTMLFormField[] array of fields (either arrays or objects) * @param string $sectionName ID attribute of the "" tag for this section, ignored if empty * @param string $fieldsetIDPrefix ID prefix for the "
" tag of each subsection, ignored if empty + * @param boolean &$hasUserVisibleFields Whether the section had user-visible fields * @return String */ - public function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '' ) { + public function displaySection( $fields, $sectionName = '', $fieldsetIDPrefix = '', &$hasUserVisibleFields = false ) { $displayFormat = $this->getDisplayFormat(); $html = ''; @@ -990,20 +991,38 @@ class HTMLForm extends ContextSource { if ( $labelValue != ' ' && $labelValue !== '' ) { $hasLabel = true; } - } elseif ( is_array( $value ) ) { - $section = $this->displaySection( $value, "mw-htmlform-$key", "$fieldsetIDPrefix$key-" ); - $legend = $this->getLegend( $key ); - if ( isset( $this->mSectionHeaders[$key] ) ) { - $section = $this->mSectionHeaders[$key] . $section; - } - if ( isset( $this->mSectionFooters[$key] ) ) { - $section .= $this->mSectionFooters[$key]; + + if ( get_class( $value ) !== 'HTMLHiddenField' && + get_class( $value ) !== 'HTMLApiField' ) { + $hasUserVisibleFields = true; } - $attributes = array(); - if ( $fieldsetIDPrefix ) { - $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" ); + } elseif ( is_array( $value ) ) { + $subsectionHasVisibleFields = false; + $section = $this->displaySection( $value, "mw-htmlform-$key", "$fieldsetIDPrefix$key-", $subsectionHasVisibleFields ); + $legend = null; + + if ( $subsectionHasVisibleFields === true ) { + // Display the section with various niceties. + $hasUserVisibleFields = true; + + $legend = $this->getLegend( $key ); + + if ( isset( $this->mSectionHeaders[$key] ) ) { + $section = $this->mSectionHeaders[$key] . $section; + } + if ( isset( $this->mSectionFooters[$key] ) ) { + $section .= $this->mSectionFooters[$key]; + } + + $attributes = array(); + if ( $fieldsetIDPrefix ) { + $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" ); + } + $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n"; + } else { + // Just return the inputs, nothing fancy. + $subsectionHtml .= $section; } - $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n"; } }