Debian Codegraph @

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

raw
1 <?php
2
3 namespace OOUI;
4
5 /**
6 * Layout made of a field, button and optional label.
7 */
8 class ActionFieldLayout extends FieldLayout {
9
10 /**
11 * Button widget to be laid out.
12 *
13 * @var Widget
14 */
15 protected $buttonWidget;
16
17 /**
18 * @var Tag
19 */
20 protected $button;
21
22 /**
23 * @var Tag
24 */
25 protected $input;
26
27 /**
28 * @param Widget $fieldWidget Field widget
29 * @param ButtonWidget|ButtonInputWidget $buttonWidget Field widget
30 * @param array $config Configuration options
31 * @suppress PhanTypeMismatchDefault Overloaded method
32 */
33 public function __construct( $fieldWidget, $buttonWidget = false, array $config = [] ) {
34 // Allow passing positional parameters inside the config array
35 if ( is_array( $fieldWidget ) && isset( $fieldWidget['fieldWidget'] ) ) {
36 $config = $fieldWidget;
37 [ 'fieldWidget' => $fieldWidget, 'buttonWidget' => $buttonWidget ] = $config;
38 }
39
40 // Parent constructor
41 parent::__construct( $fieldWidget, $config );
42
43 // Properties
44 $this->buttonWidget = $buttonWidget;
45 $this->button = new Tag( 'span' );
46 $this->input = $this->isFieldInline() ? new Tag( 'span' ) : new Tag( 'div' );
47
48 // Initialization
49 $this->addClasses( [ 'oo-ui-actionFieldLayout' ] );
50 $this->button
51 ->addClasses( [ 'oo-ui-actionFieldLayout-button' ] )
52 ->appendContent( $this->buttonWidget );
53 $this->input
54 ->addClasses( [ 'oo-ui-actionFieldLayout-input' ] )
55 ->appendContent( $this->fieldWidget );
56 $this->field
57 ->clearContent()
58 ->appendContent( $this->input, $this->button );
59 }
60
61 /** @inheritDoc */
62 public function getConfig( &$config ) {
63 $config['buttonWidget'] = $this->buttonWidget;
64 return parent::getConfig( $config );
65 }
66 }