6 * User interface control.
10 class Widget extends Element {
17 * @var boolean Widget is disabled
19 protected $disabled = false;
24 * @param array $config Configuration options
25 * @param bool $config['disabled'] Disable (default: false)
27 public function __construct( array $config = [] ) {
29 $config = array_merge( [ 'disabled' => false ], $config );
32 parent::__construct( $config );
35 $this->addClasses( [ 'oo-ui-widget' ] );
36 $this->setDisabled( $config['disabled'] );
40 * Check if the widget is disabled.
42 * @return bool Button is disabled
44 public function isDisabled() {
45 return $this->disabled;
49 * Set the disabled state of the widget.
51 * This should probably change the widgets' appearance and prevent it from being used.
53 * @param bool $disabled Disable widget
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' ] );
66 * Get an ID of a labelable node which is part of this widget, if any, to be used for
67 * `<label for>` value.
69 * @return string|null The ID of the labelable node
71 public function getInputId() {
75 public function getConfig( &$config ) {
76 if ( $this->disabled ) {
77 $config['disabled'] = $this->disabled;
79 return parent::getConfig( $config );