Implement section support for OOUIHTMLForm
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Wed, 4 Nov 2015 18:12:18 +0000 (19:12 +0100)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Wed, 4 Nov 2015 18:14:24 +0000 (19:14 +0100)
Using a PanelLayout to visually separate the outside content with
the inside one.

Bug: T117757
Change-Id: I177cd7a5f8e8ddf7dc90f452aadb804f6304b0c7

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

index e51620f..2b9a49a 100644 (file)
@@ -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;
index d328ecc..3238c2c 100644 (file)
@@ -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