summaryrefslogtreecommitdiff
path: root/vendor/oojs/oojs-ui/php/layouts/FormLayout.php
blob: ebeb89de9a7841bfd340b150cc0df0da376ff136 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace OOUI;

/**
 * Layout with an HTML form.
 */
class FormLayout extends Layout {

	/* 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 = array() ) {
		// Parent constructor
		parent::__construct( $config );

		// Mixins
		$this->mixin( new GroupElement( $this, array_merge( $config, array( 'group' => $this ) ) ) );

		// Initialization
		$attributeWhitelist = array( 'method', 'action', 'enctype' );
		$this
			->addClasses( array( 'oo-ui-formLayout' ) )
			->setAttributes( array_intersect_key( $config, array_flip( $attributeWhitelist ) ) );
		if ( isset( $config['items'] ) ) {
			$this->addItems( $config['items'] );
		}
	}

	public function getConfig( &$config ) {
		foreach ( array( 'method', 'action', 'enctype' ) as $attr ) {
			$value = $this->getAttribute( $attr );
			if ( $value !== null ) {
				$config[$attr] = $value;
			}
		}
		return parent::getConfig( $config );
	}
}