Debian Codegraph @

vendor/oojs/oojs-ui/php/layouts/FormLayout.php

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