Debian Codegraph @

vendor/oojs/oojs-ui/php/widgets/LabelWidget.php

raw
1 <?php
2
3 namespace OOUI;
4
5 /**
6 * Label widget.
7 */
8 class LabelWidget extends Widget {
9 use LabelElement;
10
11 /* Static Properties */
12
13 /** @var string */
14 public static $tagName = 'label';
15
16 /* Properties */
17
18 /**
19 * Associated input element.
20 *
21 * @var InputWidget|null
22 */
23 protected $input;
24
25 /**
26 * @param array $config Configuration options
27 * - InputWidget $config['input'] Input widget this label is for
28 */
29 public function __construct( array $config = [] ) {
30 // Parent constructor
31 parent::__construct( $config );
32
33 // Traits
34 $this->initializeLabelElement(
35 array_merge( [ 'labelElement' => $this ], $config )
36 );
37
38 // Properties
39 $this->input = $config['input'] ?? null;
40
41 // Initialization
42 if ( $this->input && $this->input->getInputId() ) {
43 $this->setAttributes( [ 'for' => $this->input->getInputId() ] );
44 }
45 $this->addClasses( [ 'oo-ui-labelWidget' ] );
46 }
47
48 /** @inheritDoc */
49 public function getConfig( &$config ) {
50 if ( $this->input !== null ) {
51 $config['input'] = $this->input;
52 }
53 return parent::getConfig( $config );
54 }
55 }