From ab69c83c641aa59dfe5e43a5f8d95b5948c59642 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 4 Nov 2015 19:12:18 +0100 Subject: [PATCH] Implement section support for OOUIHTMLForm Using a PanelLayout to visually separate the outside content with the inside one. Bug: T117757 Change-Id: I177cd7a5f8e8ddf7dc90f452aadb804f6304b0c7 --- includes/htmlform/HTMLForm.php | 14 +++++++++++++- includes/htmlform/OOUIHTMLForm.php | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index e51620f208..2b9a49a25a 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -1359,6 +1359,18 @@ class HTMLForm extends ContextSource { return $this->mMethod; } + /** + * Wraps the given $section into an user-visible fieldset. + * + * @param string $legend Legend text for the fieldset + * @param string $section The section content in plain Html + * @param array $attributes Additional attributes for the fieldset + * @return string The fieldset's Html + */ + protected function wrapFieldSetSection( $legend, $section, $attributes ) { + return Xml::fieldset( $legend, $section, $attributes ) . "\n"; + } + /** * @todo Document * @@ -1425,7 +1437,7 @@ class HTMLForm extends ContextSource { if ( $fieldsetIDPrefix ) { $attributes['id'] = Sanitizer::escapeId( "$fieldsetIDPrefix$key" ); } - $subsectionHtml .= Xml::fieldset( $legend, $section, $attributes ) . "\n"; + $subsectionHtml .= $this->wrapFieldSetSection( $legend, $section, $attributes ); } else { // Just return the inputs, nothing fancy. $subsectionHtml .= $section; diff --git a/includes/htmlform/OOUIHTMLForm.php b/includes/htmlform/OOUIHTMLForm.php index d328eccdd4..3238c2cc5f 100644 --- a/includes/htmlform/OOUIHTMLForm.php +++ b/includes/htmlform/OOUIHTMLForm.php @@ -108,6 +108,29 @@ class OOUIHTMLForm extends HTMLForm { return $html; } + protected function wrapFieldSetSection( $legend, $section, $attributes ) { + // to get a user visible effect, wrap the fieldset into a framed panel layout + $layout = new OOUI\PanelLayout( array( + 'expanded' => false, + 'padded' => true, + 'framed' => true, + 'infusable' => false, + ) ); + + $layout->appendContent( + new OOUI\FieldsetLayout( array( + 'label' => $legend, + 'infusable' => false, + 'items' => array( + new OOUI\Widget( array( + 'content' => new OOUI\HtmlSnippet( $section ) + ) ), + ), + ) + $attributes ) + ); + return $layout; + } + /** * Put a form section together from the individual fields' HTML, merging it and wrapping. * @param OOUI\\FieldLayout[] $fieldsHtml -- 2.20.1