]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - vendor/oojs/oojs-ui/php/layouts/FormLayout.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / oojs / oojs-ui / php / layouts / FormLayout.php
diff --git a/vendor/oojs/oojs-ui/php/layouts/FormLayout.php b/vendor/oojs/oojs-ui/php/layouts/FormLayout.php
new file mode 100644 (file)
index 0000000..f170e42
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace OOUI;
+
+/**
+ * Layout with an HTML form.
+ */
+class FormLayout extends Layout {
+       use GroupElement;
+
+       /* Static Properties */
+
+       public static $tagName = 'form';
+
+       /**
+        * @param array $config Configuration options
+        * @param string $config['method'] HTML form `method` attribute
+        * @param string $config['action'] HTML form `action` attribute
+        * @param string $config['enctype'] HTML form `enctype` attribute
+        * @param FieldsetLayout[] $config['items'] Items to add
+        */
+       public function __construct( array $config = [] ) {
+               // Parent constructor
+               parent::__construct( $config );
+
+               // Traits
+               $this->initializeGroupElement( array_merge( $config, [ 'group' => $this ] ) );
+
+               // Initialization
+               $attributeWhitelist = [ 'method', 'action', 'enctype' ];
+               $this
+                       ->addClasses( [ 'oo-ui-formLayout' ] )
+                       ->setAttributes( array_intersect_key( $config, array_flip( $attributeWhitelist ) ) );
+               if ( isset( $config['items'] ) ) {
+                       $this->addItems( $config['items'] );
+               }
+       }
+
+       public function getConfig( &$config ) {
+               foreach ( [ 'method', 'action', 'enctype' ] as $attr ) {
+                       $value = $this->getAttribute( $attr );
+                       if ( $value !== null ) {
+                               $config[$attr] = $value;
+                       }
+               }
+               return parent::getConfig( $config );
+       }
+}