File: Widget.php

package info (click to toggle)
mediawiki 1%3A1.39.13-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 320,416 kB
  • sloc: php: 815,516; javascript: 601,264; sql: 11,218; python: 4,863; xml: 3,080; sh: 990; ruby: 82; makefile: 78
file content (96 lines) | stat: -rw-r--r-- 2,037 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php

namespace OOUI;

/**
 * User interface control.
 *
 * @abstract
 */
class Widget extends Element {

	/* Properties */

	/**
	 * Disabled.
	 *
	 * @var bool Widget is disabled
	 */
	protected $disabled = false;

	/* Methods */

	/**
	 * @param array $config Configuration options
	 *      - bool $config['disabled'] Disable (default: false)
	 */
	public function __construct( array $config = [] ) {
		// Parent constructor
		parent::__construct( $config );

		// Initialization
		$this->addClasses( [ 'oo-ui-widget' ] );
		$this->setDisabled( $config['disabled'] ?? false );
	}

	/**
	 * Check if the widget is disabled.
	 *
	 * @return bool Button is disabled
	 */
	public function isDisabled() {
		return $this->disabled;
	}

	/**
	 * Set the disabled state of the widget.
	 *
	 * This should probably change the widgets' appearance and prevent it from being used.
	 *
	 * @param bool $disabled Disable widget
	 * @return $this
	 */
	public function setDisabled( $disabled ) {
		$this->disabled = (bool)$disabled;
		$this->toggleClasses( [ 'oo-ui-widget-disabled' ], $this->disabled );
		$this->toggleClasses( [ 'oo-ui-widget-enabled' ], !$this->disabled );
		if ( $this->disabled ) {
			$this->setAttributes( [ 'aria-disabled' => 'true' ] );
		} else {
			$this->removeAttributes( [ 'aria-disabled' ] );
		}

		return $this;
	}

	/**
	 * Get an ID of a labelable node which is part of this widget, if any, to be used for
	 * `<label for>` value.
	 *
	 * @return string|null The ID of the labelable node
	 */
	public function getInputId() {
		return null;
	}

	/**
	 * Set the element with the given ID as a label for this widget.
	 *
	 * @param string|null $id
	 */
	public function setLabelledBy( $id ) {
		if ( $id ) {
			$this->setAttributes( [ 'aria-labelledby' => $id ] );
		} else {
			$this->removeAttributes( [ 'aria-labelledby' ] );
		}
	}

	/** @inheritDoc */
	public function getConfig( &$config ) {
		if ( $this->disabled ) {
			$config['disabled'] = $this->disabled;
		}
		return parent::getConfig( $config );
	}
}