Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
HTMLFormElement | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
initializeHTMLFormElement | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm; |
4 | |
5 | /** |
6 | * Allows custom data specific to HTMLFormField to be set for OOUI forms. A matching JS widget |
7 | * (defined in htmlform.Element.js) picks up the extra config when constructed using OO.ui.infuse(). |
8 | * |
9 | * Currently only supports passing 'hide-if' and 'disable-if' data. |
10 | * @phan-file-suppress PhanUndeclaredMethod |
11 | * |
12 | * @stable to extend |
13 | */ |
14 | trait HTMLFormElement { |
15 | |
16 | protected $condState = null; |
17 | protected $modules = null; |
18 | |
19 | public function initializeHTMLFormElement( array $config = [] ) { |
20 | // Properties |
21 | $this->condState = $config['condState'] ?? []; |
22 | $this->modules = $config['modules'] ?? []; |
23 | |
24 | // Initialization |
25 | if ( $this->modules ) { |
26 | // JS code must be able to read this before infusing (before OOUI is even loaded), |
27 | // so we put this in a separate attribute (not with the rest of the config). |
28 | // And it's not needed anymore after infusing, so we don't put it in JS config at all. |
29 | $this->setAttributes( [ 'data-mw-modules' => implode( ',', $this->modules ) ] ); |
30 | } |
31 | $this->registerConfigCallback( function ( &$config ) { |
32 | if ( $this->condState ) { |
33 | $config['condState'] = $this->condState; |
34 | } |
35 | } ); |
36 | } |
37 | } |
38 | |
39 | /** @deprecated class alias since 1.42 */ |
40 | class_alias( HTMLFormElement::class, 'HTMLFormElement' ); |