]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/oojs/oojs-ui/php/Widget.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / oojs / oojs-ui / php / Widget.php
1 <?php
2
3 namespace OOUI;
4
5 /**
6  * User interface control.
7  *
8  * @abstract
9  */
10 class Widget extends Element {
11
12         /* Properties */
13
14         /**
15          * Disabled.
16          *
17          * @var boolean Widget is disabled
18          */
19         protected $disabled = false;
20
21         /* Methods */
22
23         /**
24          * @param array $config Configuration options
25          * @param bool $config['disabled'] Disable (default: false)
26          */
27         public function __construct( array $config = [] ) {
28                 // Initialize config
29                 $config = array_merge( [ 'disabled' => false ], $config );
30
31                 // Parent constructor
32                 parent::__construct( $config );
33
34                 // Initialization
35                 $this->addClasses( [ 'oo-ui-widget' ] );
36                 $this->setDisabled( $config['disabled'] );
37         }
38
39         /**
40          * Check if the widget is disabled.
41          *
42          * @return bool Button is disabled
43          */
44         public function isDisabled() {
45                 return $this->disabled;
46         }
47
48         /**
49          * Set the disabled state of the widget.
50          *
51          * This should probably change the widgets' appearance and prevent it from being used.
52          *
53          * @param bool $disabled Disable widget
54          * @return $this
55          */
56         public function setDisabled( $disabled ) {
57                 $this->disabled = !!$disabled;
58                 $this->toggleClasses( [ 'oo-ui-widget-disabled' ], $this->disabled );
59                 $this->toggleClasses( [ 'oo-ui-widget-enabled' ], !$this->disabled );
60                 $this->setAttributes( [ 'aria-disabled' => $this->disabled ? 'true' : 'false' ] );
61
62                 return $this;
63         }
64
65         /**
66          * Get an ID of a labelable node which is part of this widget, if any, to be used for
67          * `<label for>` value.
68          *
69          * @return string|null The ID of the labelable node
70          */
71         public function getInputId() {
72                 return null;
73         }
74
75         public function getConfig( &$config ) {
76                 if ( $this->disabled ) {
77                         $config['disabled'] = $this->disabled;
78                 }
79                 return parent::getConfig( $config );
80         }
81 }