1<?php
2
3namespace OOUI;
4
5/**
6 * Layout with an HTML form.
7 */
8class FormLayout extends Layout {
9	use GroupElement;
10
11	/* Static Properties */
12
13	public static $tagName = 'form';
14
15	/**
16	 * @param array $config Configuration options
17	 *      - string $config['method'] HTML form `method` attribute
18	 *      - string $config['action'] HTML form `action` attribute
19	 *      - string $config['enctype'] HTML form `enctype` attribute
20	 *      - FieldsetLayout[] $config['items'] Items to add
21	 */
22	public function __construct( array $config = [] ) {
23		// Parent constructor
24		parent::__construct( $config );
25
26		// Traits
27		$this->initializeGroupElement( array_merge( [ 'group' => $this ], $config ) );
28
29		// Initialization
30		$attributeWhitelist = [ 'method', 'action', 'enctype' ];
31		$this
32			->addClasses( [ 'oo-ui-formLayout' ] )
33			->setAttributes( array_intersect_key( $config, array_flip( $attributeWhitelist ) ) );
34		if ( isset( $config['items'] ) ) {
35			$this->addItems( $config['items'] );
36		}
37	}
38
39	public function getConfig( &$config ) {
40		foreach ( [ 'method', 'action', 'enctype' ] as $attr ) {
41			$value = $this->getAttribute( $attr );
42			if ( $value !== null ) {
43				$config[$attr] = $value;
44			}
45		}
46		return parent::getConfig( $config );
47	}
48}
49