]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - vendor/oojs/oojs-ui/php/widgets/LabelWidget.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / vendor / oojs / oojs-ui / php / widgets / LabelWidget.php
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         public static $tagName = 'label';
14
15         /* Properties */
16
17         /**
18          * Associated input element.
19          *
20          * @var InputWidget|null
21          */
22         protected $input;
23
24         /**
25          * @param array $config Configuration options
26          * @param InputWidget $config['input'] Input widget this label is for
27          */
28         public function __construct( array $config = [] ) {
29                 // Parent constructor
30                 parent::__construct( $config );
31
32                 // Traits
33                 $this->initializeLabelElement(
34                         array_merge( $config, [ 'labelElement' => $this ] ) );
35
36                 // Properties
37                 $this->input = isset( $config['input'] ) ? $config['input'] : null;
38
39                 // Initialization
40                 if ( $this->input && $this->input->getInputId() ) {
41                         $this->setAttributes( [ 'for' => $this->input->getInputId() ] );
42                 }
43                 $this->addClasses( [ 'oo-ui-labelWidget' ] );
44         }
45
46         public function getConfig( &$config ) {
47                 if ( $this->input !== null ) {
48                         $config['input'] = $this->input;
49                 }
50                 return parent::getConfig( $config );
51         }
52 }