Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / htmlform / HTMLFormElement.php
1 <?php
2
3 /**
4 * Allows custom data specific to HTMLFormField to be set for OOUI forms. A matching JS widget
5 * (defined in htmlform.Element.js) picks up the extra config when constructed using OO.ui.infuse().
6 *
7 * Currently only supports passing 'hide-if' data.
8 * @phan-file-suppress PhanUndeclaredMethod
9 */
10 trait HTMLFormElement {
11
12 protected $hideIf = null;
13 protected $modules = null;
14
15 public function initializeHTMLFormElement( array $config = [] ) {
16 // Properties
17 $this->hideIf = $config['hideIf'] ?? null;
18 $this->modules = $config['modules'] ?? [];
19
20 // Initialization
21 if ( $this->hideIf ) {
22 $this->addClasses( [ 'mw-htmlform-hide-if' ] );
23 }
24 if ( $this->modules ) {
25 // JS code must be able to read this before infusing (before OOUI is even loaded),
26 // so we put this in a separate attribute (not with the rest of the config).
27 // And it's not needed anymore after infusing, so we don't put it in JS config at all.
28 $this->setAttributes( [ 'data-mw-modules' => implode( ',', $this->modules ) ] );
29 }
30 $this->registerConfigCallback( function ( &$config ) {
31 if ( $this->hideIf !== null ) {
32 $config['hideIf'] = $this->hideIf;
33 }
34 } );
35 }
36 }